Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Good Intentions: Wikisyntax for the Monastery

by LanX (Saint)
on Jan 27, 2016 at 23:44 UTC ( [id://1153804]=monkdiscuss: print w/replies, xml ) Need Help??

One of my New Year's resolutions is to release more code, even if it doesn't meet my quality expectations yet... ¹

I'm using this hack for some time now...

It's a nodelet hack which automatically transforms my wiki-ish syntax into monk-code on submit.

This is done transparently because after a reload the monk-code in the textarea is translated back to the original wiki syntax.

Please note that you can still safely use and blend PM-markup as long as you use lowercase characters. The automatically transformed code is always uppercase.

The biggest benefit is that paragraphs <P> are automatically included between two newlines...

...but I added some more goodies over the years. (see examples further down.)

To activate this for yourself you just need to include the following code into your free nodelet.

<script src='?abspart=1;displaytype=displaycode;node_id=1153804;part=3'></script>

(UPDATE: Additionally the "Free Nodelet" must be activated at Nodelet Settings)

I hope the mechanism of the code is obvious enough to be adapted to your needs.

---Code---

---Demo---

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

update

codelink corrected, including another codearea changed the index to 3

footnotes

¹) there is a long To-Do list left, but the idea of open source is to attract collaborators and/or forks ... right? ;-)

bugfixes

  • surrounded activation of JS events with if(textarea) { ... } to avoid pages without posting forms (like RAT)

Replies are listed 'Best First'.
Re: Good Intentions: Wikisyntax for the Monastery
by Discipulus (Canon) on Jan 28, 2016 at 09:13 UTC
    Wow! thanks!

    I'll try it as soon as i can. for the code part i can't offer help but you'have my user's feedback

    L*

    UPDATE: it works like a charm, To use it you have to:

    1. As said in the OP: To activate this for yourself you just need to include the following code into your Free Nodelet Settings.

      <script src='?abspart=1;displaytype=displaycode;node_id=1153804;part=3'></script>

    2. Go to Nodelet Settings and put the two Free Nodelet to something non zero

    LanX it does not work for nested tags? <li>Go to [id://25185] and put the two *Free Nodelet* to something non zero</li> shows:
    2. Go to Nodelet Settings and put the two *Free Nodelet* to something +non zero


    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
      > LanX it does not work for nested tags?

      It does , but currently only for one word. (see the regex singleword in the code)

      The problem are longer strings, the number of misinterpretations will occur far more often if one allows more than 1 word. Where do I have to draw the line? 3, 4 words ...?

      I was thinking of using doubled symbols like ** instead of * for longer passages, like in wikicreole

      The goal is to make the syntax rules customizable for the user.²

      In the end <b><i><u> are not really that important, the other features are far more relevant when typing on a mobile device.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

      update

      Thanks for your interest and contribution! :)

      footnotes
      ²) did I mention my to-do list ? ;-)
        Also
        'ARGV'<br>
        seems not to behave correctly: just to add to todo list

        your code is in production for me anyway

        L*

        There are no rules, there are no thumbs..
        Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: Good Intentions: Wikisyntax for the Monastery (ToDo)
by LanX (Saint) on Jan 28, 2016 at 14:55 UTC
    Todos in the pipline / wishlist

    General
    • cleaner code to avoid namespace pollution
    • create Perl version which is auto-translated to JS-version
    • auto create documentation of syntax
    • test suite also checking browsers
    • move to git-hub
    • allow individual customizing of allowed features and used markup
    • allow caching of imported JS to spare band width
    • general JS-Extension framework to encourage more contributions, see also older discussion
    More Features
    • DONE auto link URLs starting with http://
    • DONE parse for internal url's and create [id://...] links (thus avoiding logouts)
    • map doc-links of operators to correct perldoc, like ?and? to [doc://perlop|and]
    • support for abbreviation list, i.e. auto linking autolinking SOPW or CPAN with mouseover (' title' -attribute) description
    • better support for quotes from commented post
    • onchange preview with JS of resulting post
    • looks-like-code() heuristic to warn about perlcode outside code-blocks
    • move [ ]wiki? checkbox under textarea, show only if any submit button available
    • include timestamp after updates
    • DONE support for deeplinks in perldocs (jump to right chapter)
    • better support for cut&paste from perldoc (web or console)

    ... to be continued...

    Requested
    • Wiki support for CB
    • look behind assertion in around_words
    • treat punctuation like whitespace

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

      *The* first word in the post can't have the bold/italic/underline formatting. Unless there's a space or empty line before it. If it's an empty line, that line disappears after previewing, and then the formatting stops working. A single space will remain.

      I don't mean to whine; I like this immensely.

      But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

        Yeah I know I got used to adding a space before the first line and after the last.

        I already mentioned that problem, but ...

        ... I did'nt want to expand the regexes to other whitespaces for that ATM because that's a PITA to test in different browsers.

        It might become configurable in the future, but without guaranty whatsoever.

        Anyway the "bold/italic/underline formatting" isn't that important for me, being able to avoid <p> while typing in my mobile is already worth it. ;-)

        Naming this PM extension a "wiki" might be a misnomer/marketing error though... ;-)

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!

        > If it's an empty line, that line disappears after previewing,

        this certainly looks like a bug, THANK YOU! :)

        UPDATE

        So it's not my wiki code causing it.

        I tested as anomonk and the content of the textarea is trimmed from surrounding newlines.

        maybe it's the monasteries codebase ... maybe a firefox thing.

        for the time being, please use an extra whitespace.

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!

        First word works now, also does the last
        Actually I've always had in mind that a server side Perl version might be needed and put effort into realizing the logic as a cascade of RegExes.

        RegExes in JS are 98% based on the Perl4 standard. ( exceptions are things like [^] )

        So it shouldn't be too difficult and fun too.

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!

      What is the intended use of the wiki checkbox in CB?

      But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

        To be able to switch the wiki transformation manually on or off.

        It could be better placed below the textarea, but this was already mentioned in the todo list.

        NB : it's not in the CB but in the Free Nodelet.

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!

Re: Good Intentions: Wikisyntax for the Monastery (New Features)
by LanX (Saint) on Feb 02, 2016 at 00:10 UTC
    New Features:

    emphasizer B U I span extended
    Now one line instead of one word

    Link activation

    Pasted URLs are automatically linked,

     http://www.google.com
    =>  [HTTP://www.google.com]
    == http://www.google.com

     http://perldoc.perl.org/perlsyn.html#Loop-Control
    => [HTTP://perldoc.perl.org/perlsyn.html#Loop-Control|perlsyn#Loop-Control]
    == perlsyn#Loop-Control

     http://www.perlmonks.org/?node_id=708738
    =>  [ID://708738]
    == LanX

     http://www.perlmonks.org/?node_id=708738|test
    =>  [ID://708738|test]
    == test

    Version data included (hidden)

    <!-- wiki2monks JSON-DATA --> is inserted at end of post

    Avoid wikification

    <nowiki></nowiki> tags

    List items (under construction)

    - one - two - three
    • one
    • two
    • three
    + one - two - three

    1. one
    2. two
    3. three

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

    update 2016-02-12

    added optional index.pl to regex for PM URLs

     http://www.perlmonks.org/index.pl?node_id=708738
    =>  [ID://708738]
    == LanX

Re: Good Intentions: Wikisyntax for the Monastery
by Discipulus (Canon) on Feb 12, 2016 at 09:03 UTC
    Ok before i forget this: it seems that three code elements in a row are not displaying correctly.

    For example

    'one' 'two' 'three'
    is displayed as one 'two' three

    I was also wondering if you can add punctuation ( .,:;)(!? ) as boundary in addition to withespace. I'm using your wiki syntax in every post. thanks

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
      Hi

      Thanks for feedback! =)

      regarding code sections:

      Problem is that JS has no lookbehind assertion for regex.

      In order to keep it simple and compatible I'm grabbing the surrounding white spaces too.

      If you separate your code by more then one whitespace it works again.

      'one'  'two'  'three'

      one two three

      please note how HTML ignores multiple whitespace.

      (This is a very contrived example anyway don't you think? ;)

      I could solve this with at least one look ahead assertion, though I'm not sure about incompatibilities. (on todo list now)

      Please keep in mind that you can still use the old and consistent markup.

      The wiki stuff is more a mix of DWIM and Huffman coding, not a complete replacement. =)

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

      > I was also wondering if you can add punctuation ( .,:;)(!? ) as boundary in addition to withespace. 

      Yes I was thinking about this, but than we need a new mark up for doc links

       ?print? print

      Suggestions?

      update

      But please be aware that the problem with look around assertions strikes here again.

      I have no problem with coding this, but testing would be a pain. ..

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

        I think # is faster to type but question mark is definitively more related to documentation. I'd go for it.

        PS sorry i'v a bit misunderstood (question mark yet used for doclinks). # as for comments? or = as for POD?

        Also a comprensive cheetsheet will be useful at the end of your OP

        L*

        There are no rules, there are no thumbs..
        Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: Good Intentions: Wikisyntax for the Monastery
by FreeBeerReekingMonk (Deacon) on Jan 29, 2016 at 22:33 UTC
    Just here to say that I find wiki syntax fantastic and this is *GREAT*
      Thank you ! :)

      So you are using it?

      (except of this post ;)

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

        I try to, but I did not post much. (update: yay! working now)
Re: Good Intentions: Wikisyntax for the Monastery (https)
by LanX (Saint) on Jun 22, 2018 at 18:00 UTC
    Added (long overdue) support for https when autolinking

    This

    - https://perldoc.perl.org/perldiag.html - http://perldoc.perl.org/perldiag.html - https://perldoc.perl.org/perldiag.html#DESCRIPTION - http://perldoc.perl.org/perldiag.html#DESCRIPTION - https://www.zeit.de/sport/2018-06/wm-2018-fussball-liveticker#/live - http://www.zeit.de/sport/2018-06/wm-2018-fussball-liveticker#/live - https://www.perlmonks.org/?node_id=708738 - http://www.perlmonks.org/?node_id=708738

    transforms to

    - [HTTPs://perldoc.perl.org/perldiag.html|perldiag] - [HTTP://perldoc.perl.org/perldiag.html|perldiag] - [HTTPs://perldoc.perl.org/perldiag.html#DESCRIPTION|perldiag#DESCRIP +TION] - [HTTP://perldoc.perl.org/perldiag.html#DESCRIPTION|perldiag#DESCRIPT +ION] - [HTTPs://www.zeit.de/sport/2018-06/wm-2018-fussball-liveticker#/live +] - [HTTP://www.zeit.de/sport/2018-06/wm-2018-fussball-liveticker#/live] - [ID://708738] - [ID://708738]
    and shows as

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Re: Good Intentions: Wikisyntax for the Monastery
by LanX (Saint) on Feb 08, 2020 at 00:15 UTC
    <nowiki> tags are now automatically transformed to <!--nowiki--> comments (which acts as an alias).

    Hence they don't display anymore in the resulting posting, see also Re^2: Good Intentions: Wikisyntax for the Monastery


    <-- this input
    <nowiki> === headline1 </nowiki> === headline2


    --> renders now as

    === headline1

    headline2

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Re: Good Intentions: Wikisyntax for the Monastery
by choroba (Cardinal) on Oct 18, 2016 at 10:19 UTC
    Bugreport:

    PRE tags don't block expansion of single quotes:

    <c> perl -we 'say' </c> <pre> perl -we 'say' </pre>

    Update: rendered as

    perl -we 'say'

    perl -we say
    

    See? No single quotes in the last line!

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
      Hi

      I just noticed that <pre> tags allowed that <p> tags were included which is against the meaning of "pre-formatting".

      pre-blocks are now excluded from any wiki-expansion

      <pre> *a* /b/ # 2 newlines following https://perlmonks.org/ </pre>

      displays now as

      *a* /b/
      # 2 newlines following
      
      https://perlmonks.org/
      

      update

      <blockquote> are now also excluded, but that's experimental.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      Rather a feature request, don't you think?

      Why should pre tags be handled like code tags? °

      AFAIR do pre tags never block any other expansion, I wouldn't know why they should.

      Could you please elaborate?

      Edit:

      Please think about how

      <pre>a <code>bla</code> b</pre>

      is rendered


      a
      bla
      b

      and tell me why the behavior should be different now.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

      update Feb 07 2020

      °) OK paragraph is a reason, see Re^2: Good Intentions: Wikisyntax for the Monastery (pre-blocks excluded now)

      I think this is close to what you want.

      I have only to find a way to make nowiki invisible in output but persistent in edit mode.

      <nowiki> <pre> perl -we 'say' </pre> </nowiki>


      <nowiki>

       
      
      perl -we 'say' 
      
      
      </nowiki>

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

        Wrap it in <!-- ... -->?

        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re: Good Intentions: Wikisyntax for the Monastery (issue: "writeln wiki-toggle")
by LanX (Saint) on Feb 13, 2020 at 00:37 UTC
    I'm experiencing a new issue in Firefox.

    The generated HTML tags in the textarea are not translated back to wiki syntax when onLoad fires.

    A look into the console logs reveals that

    "A call to document.write() from an asynchronously-loaded external script was ignored".

    This originates from the creation of the checkbox to switch wikiparser on/off.

    I will try to bypass that...

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      V1.16.0

      I deactivated the document.writeln into the "Free Nodelet" and replaced it with an append to outerHTML in the form area.

      The Wiki toggle is now just next to the submit buttons under the textarea.

      This was on the To-Do list anyway.

      Works fine in FF, please test in other browsers. :)

      Update

      tested in

      ==== Desktop

      • Firefox/72.0
      ==== Mobile
      • Chrome

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

        Maybe have the <b>*Wiki?*</b> be a link back to Good Intentions: Wikisyntax for the Monastery, in case someone forgets their Wiki syntax from one visit to the next. :-)

        Also, the syntax accepted by the nodelet hack seems to be split between the spoiler of the original post and a reply (and here for https extension, and probably other posts that I haven't noticed). It makes it rather disjointed to see what's translated by the nodelet hack. It might be nice to have all the currently-valid syntax summarized somewhere in the root post (maybe in a third section alongside code and demo sections) -- or at least update demo with the additional linking options and the features like <nowiki> which have been added over time.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: monkdiscuss [id://1153804]
Front-paged by stevieb
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2024-03-19 06:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found