Advertisements

WordPress Source Code Test Post, “Improved” Editor

This was created with the “improved” editor… to show WP support some of the problems I’m fighting on a regular basis.

So here’s a picture, just for fill:

Mood Light - thermocouple location

Mood Light – thermocouple location

It’s worth noting that you (well, I) cannot add this post text after that picture in Visual mode, because the “last character” is inside the picture caption: whatever I type appears in the caption. Switching to HTML mode, starting this sentence, then switching back to Visual mode, is the only way to go.

Here’s the same block of code, pasted in Visual mode:


void loop() {

MillisNow = millis();
if ((MillisNow - MillisThen) > UpdateMS) {
digitalWrite(PIN_HEARTBEAT,HIGH);

for (byte c=0; c < PIXELSIZE; c++) { // step to next increment in each color
if (++Pixels[c].Step >= Pixels[c].NumSteps) {
Pixels[c].Step = 0;
printf("Cycle %d steps %d at %8ld delta %ld ms\r\n",c,Pixels[c].NumSteps,MillisNow,(MillisNow - MillisThen));
}
}

for (int i=0; i < LEDSTRINGCOUNT; i++) { // for each layer
byte Value[PIXELSIZE];
for (byte c=0; c < PIXELSIZE; c++) { // ... for each color
Value[c] = StepColor(c,-i*Pixels[c].PlatterPhase); // figure new PWM value
// Value[c] = (c == RED && Value[c] == 0) ? Pixels[c].MaxPWM : Value[c]; // flash highlight for tracking
}
uint32_t UniColor = strip.Color(Value[RED],Value[GREEN],Value[BLUE]);
if (false && (i == 0))
printf("L: %d C: %08lx\r\n",i,UniColor);
for (int j=0; j < LEDSTRIPCOUNT; j++) { // fill layer with color
strip.setPixelColor(Map[i][j],UniColor);
}
}
strip.show();

MillisThen = MillisNow;
digitalWrite(PIN_HEARTBEAT,LOW);
}

}

The editor strips all the leading tabs and left-justifies all the lines. Tabs within the lines vanish, too, so all the comments slide leftward against the preceding code.

Here’s the same block, pasted in Visual mode with “Paste as text” turned on:


void loop() {

MillisNow = millis();
if ((MillisNow - MillisThen) > UpdateMS) {
digitalWrite(PIN_HEARTBEAT,HIGH);

for (byte c=0; c < PIXELSIZE; c++) { // step to next increment in each color
if (++Pixels[c].Step >= Pixels[c].NumSteps) {
Pixels[c].Step = 0;
printf("Cycle %d steps %d at %8ld delta %ld ms\r\n",c,Pixels[c].NumSteps,MillisNow,(MillisNow - MillisThen));
}
}

for (int i=0; i < LEDSTRINGCOUNT; i++) { // for each layer
byte Value[PIXELSIZE];
for (byte c=0; c < PIXELSIZE; c++) { // ... for each color
Value[c] = StepColor(c,-i*Pixels[c].PlatterPhase); // figure new PWM value
// Value[c] = (c == RED && Value[c] == 0) ? Pixels[c].MaxPWM : Value[c]; // flash highlight for tracking
}
uint32_t UniColor = strip.Color(Value[RED],Value[GREEN],Value[BLUE]);
if (false && (i == 0))
printf("L: %d C: %08lx\r\n",i,UniColor);
for (int j=0; j < LEDSTRIPCOUNT; j++) { // fill layer with color
strip.setPixelColor(Map[i][j],UniColor);
}
}
strip.show();

MillisThen = MillisNow;
digitalWrite(PIN_HEARTBEAT,LOW);
}

}

Obviously, that had no effect whatsoever: all the tabs vanish.

Here’s the same block, pasted in HTML mode:

void loop() {

MillisNow = millis();
if ((MillisNow - MillisThen) > UpdateMS) {
digitalWrite(PIN_HEARTBEAT,HIGH);

for (byte c=0; c < PIXELSIZE; c++) { // step to next increment in each color if (++Pixels[c].Step >= Pixels[c].NumSteps) {
Pixels[c].Step = 0;
printf("Cycle %d steps %d at %8ld delta %ld ms\r\n",c,Pixels[c].NumSteps,MillisNow,(MillisNow - MillisThen));
}
}

for (int i=0; i < LEDSTRINGCOUNT; i++) { // for each layer
byte Value[PIXELSIZE];
for (byte c=0; c < PIXELSIZE; c++) { // ... for each color
Value[c] = StepColor(c,-i*Pixels[c].PlatterPhase); // figure new PWM value
// Value[c] = (c == RED && Value[c] == 0) ? Pixels[c].MaxPWM : Value[c]; // flash highlight for tracking
}
uint32_t UniColor = strip.Color(Value[RED],Value[GREEN],Value[BLUE]);
if (false && (i == 0))
printf("L: %d C: %08lx\r\n",i,UniColor);
for (int j=0; j < LEDSTRIPCOUNT; j++) { // fill layer with color
strip.setPixelColor(Map[i][j],UniColor);
}
}
strip.show();

MillisThen = MillisNow;
digitalWrite(PIN_HEARTBEAT,LOW);
}

}

When pasted, that looked correct, but switching back to Visual mode, even without doing any editing, stripped out all the tabs again.

Oh, and something is escaping the ampersand characters over and over again.

So, obviously, nobody has ever tested the “improved” editor against source code blocks.

Incidentally, the Visual and HTML tabs scroll off the top, but pressing Ctrl-Home scrolls only within this narrow text window. Scrolling to the top requires mouse manipulation: click outside the text column, then whack Ctrl-Home. All that, just to switch modes.

Advertisements
  1. #1 by solaandjin on 2015-12-17 - 15:10

    Have you tried enabling Markdown and just using that? I don’t know if it’s to your taste, but since it probably involves a little less magic, it might survive all the roundtrip processing a little better. https://en.support.wordpress.com/markdown/

    Code blocks are marked off with three backticks and a language if you want syntax highlighting (““`cpp”).

    • #2 by Ed on 2015-12-17 - 21:47

      The short answer is “no”.

      The longer answer: the only way to use Markdown is to email the posts to a special address I’d have to set up. WP support says that if you then want to edit the resulting post, you must use only the text mode of the “improved” editor and, seeing as how that’s not the default mode, if you slip up even once, they admit it will shred the Markdown syntax.

      Which seems even more delicate than what I’m doing now and not worth the effort.

      I’m not making this stuff up, BTW…

      • #3 by solaandjin on 2015-12-18 - 01:17

        Really! I’m quite surprised. So, fully cognizant that I don’t have a WordPress blog and you do, what about the sections in that document I linked to that say:

        To enable Markdown for posts and pages, go to Settings → Writing in your dashboard, and check the box labeled Use Markdown for posts and pages. Click on Save Changes at the bottom of the page to apply. You will now be able compose posts and pages using Markdown.

        and:

        The original Markdown text you write will always remain in Markdown, this way you can go back and edit it using Markdown. Only the published document – the post or the page – will be converted. If you write a post in Markdown, it will be published as a fully formatted post on your blog, but when you go back and edit, it’ll still be in Markdown.

        • #4 by Ed on 2015-12-18 - 09:50

          I’m quite surprised.

          Me, too.

          Markdown, like Python, depends on semantic whitespace: indentation matters. The editors ruthlessly destroy whitespace, both leading and embedded, and wreck any preformatted layout. Bonus: they erratically convert characters to their HTML-escaped “equivalents”, from which there is no return; see my continuing problems with greater-than, less-than, and ampersand characters.

          There’s no “undo”, because the editor misunderstands what you typed: the destruction happens internal to the editor, where it can’t be undone.

          You must use the editors, if only to tweak the post’s metadata, and that’s enough to kill the contents.

          Because you don’t need source code to post cat pictures, what I’m trying to do lies far outside WP’s intended use case. [sigh]

          • #5 by solaandjin on 2015-12-18 - 15:22

            Have you looked into “offline editors” at all? I see there’s one called BloGTK for Linux: https://en.support.wordpress.com/xml-rpc/

            There is also weblogger mode for Emacs, which I hesitate to mention because it’s such an acquired taste.

            • #6 by Ed on 2015-12-18 - 17:23

              offline editors

              The free wordpress.com blogs work this way: you must use their infrastructure and you have no choice in how things operate. Although you can compose posts offline, you must use their web-based editors for updates / metadata tweakage. Because WP controls the infrastructure, you cannot install any of the WordPress.org plugins / extensions available for your own WP installation.

              I could spin up a Digital Ocean (*) Linux droplet, install WordPress, aim softsolder.com at that IP, take on sysadmin (and spam repelling) duties, and pay to to do a bunch of distracting activities I don’t enjoy, instead of just documenting what I’m doing around here so I can find my notes again. [sigh]

              The Official Recommendation for WP source code now involves creating gists on GitHub, which means my content gets spread across two sites. Worse, a typical post might involve several snippets that count as separate source code blocks: I’d be ankle-deep in gists after a month. I might do that for the bulk listings at the bottom of posts involving solid models & Arduino programs; some experimentation seems in order.

              (*) One of the guys at Squidwrench works for DO…

  1. Merry Catmas! | The Smell of Molten Projects in the Morning