[pmwiki-users] On the order of Markup

Peter Kay pkay42 at gmail.com
Thu Mar 23 10:21:06 CDT 2017


Background:

I was writing a quick little bit of markup to let me put in a sidebar
(textbox on the right side of an article, not the skin's Sidebar), and
hammered out something that would replace

(:sidebar Title
blah blah
:)

with

>>rframe width=30pct<<
Title
blah blah etc
>><<

Due to the way pmwiki handles spacing and multi-line markup, I
specified it needed to run "<split".

All was fine, until I added one as the very first line on a page -
suddenly, the markup didn't work.

It seemed my pattern ('/^\(:sidebar ...') wasn't matching for some
reason.  After further digging (I'm a curious person) I discovered
that the default $GroupHeaderFmt='(:include {$Group}.GroupHeader
self=0 basepage={*$FullName}:)(:nl:)' is prepended to the page and
that (:nl:) was showing up at the very beginning of the page before my
markup ran, so instead of
(:sidebar Title
etc
:)
my markup was passing over
(:nl:)(:sidebar Title
etc
:)
My markup pattern no longer finds (:sidebar ... because it is no
longer at the beginning of a line.

(As an aside, this was NOT happening when the first character of the
page was not a parenthesis - if my markup was Xsidebar ... then it
worked just fine.  I'm still not quite sure why this was happening)

I was confused as to why the (:nl:) was not being replaced by \n.
After all, my markup was specified to run before split.  And so was
"nl0" - and I knew that "nl0" was happening before my markup.  The
"nl1" markup was specified to run after "nl0", and "nl1" should have
been clearing the (:nl:) markup, and my (:sidebar ...:) should have
worked.

What's going on:

The markup ruleset is being ordered in a surprising (to me) way:

textvar:       <split           B>><
nl0              <split           B>><
Sidebar          <split           B>><
input+sp         <split           B>><
nl1              >nl0             B>><>

That is, everything that is "before split" is grouped together.  Then
everything that is after any member of that group is grouped together.

So while "nl1" is specified to run ">nl0" it's really running ">"
textvar: and nl0 and Sidebar and input+sp.  If I add "Test" markup
">Sidebar" it will happen in the same group as "nl1".

I am wondering:

Is there any particular benefit to this non-intuitive approach to
ordering markup?  A tree structure strikes me as the more intuitive
way to order things, with each node having "before" and "after"
branches.  Then MarkupToHTML can traverse the tree and "nl1" will
happen immediately after "nl0".

If there's no reason not to, if an enterprising author were to write
the necessary changes, would we add them to pmwiki?

In the meantime, I will be specifying my sidebar to run ">nl1" which
looks a bit odd, but works.

Afterthought:

If any other cookbook authors have written recipes with multiline
markup and haven't tested it on the first line of a page, my original
problem might not be isolated.  Adding a newline to the end of
GroupHeaderFmt would also solve this.

Likewise, adding a newline to the beginning of GroupFooterFmt might be wise.

--Peter Kay



More information about the pmwiki-users mailing list