Re: Markdown ultra-lite
On Tue, Nov 7, 2017 at 2:20 AM, Trevor DeVore via use-livecode wrote: > > Here is some old code I used in the past which was modified from some other > converted I had written for Textile and BBCode. Trevor, thank you very much. >If I were writing the > converter today I would use the styledText array to do it. It is great for > converting to other formats. > Yes, that is what my initial, very basic, play around has used. The nice thing about having your code is that I can feed some HTML in, see what comes out of your code and then compare that against my own results. It's I nice check to confirm I understand what I think the markdown spec is saying;-) It'll save me time so thanks again. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Markdown ultra-lite
Yeah, that's a really good suggestion. I had thought of it - but the purist in me was reluctant to add a "magic character sequence" without any escape mechanism. And the limitation of "no whitespace" made it tricky to limit the context of the replace. However - the fact that you made the suggestion has bolstered the pragmatist in me, so currently the pragmatist is winning over the purist :-) Indeed, I'll make the character sequence be "_NEW_TAB_" - and then it feels like enhanced readability, so it's a feature :-) Thanks. And (yet again) thanks to this list for the help and suggestions people are willing to put time into ... Alex. On 06/11/2017 13:57, James At The Hale via use-livecode wrote: Alex wrote a trailing "*" in a URL would be converted to make the link open in a new browser tab/window - by changing it to? TARGET="_blank" Couldn’t you simply replace your suitably chosen trailing characters with TARGET="_blank" after using the function? (I mention characters as a single * might be used elsewhere.) James ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Markdown ultra-lite
On Sun, Nov 5, 2017 at 2:40 PM, Kay C Lan via use-livecode < use-livecode@lists.runrev.com> wrote: > Nor was I aware that mergMardownToXHMTL existed, so thank you for > raising this thread so James could enlighten us. Now all I need is > someone to tell me there is similar function that converts HTML (or > more specifically the LC subset of HTML used by Fields) to Markdown > otherwise I too will be reading more about Markdown (thanks for the > link) and learning something new. Here is some old code I used in the past which was modified from some other converted I had written for Textile and BBCode. If I were writing the converter today I would use the styledText array to do it. It is great for converting to other formats. https://gist.github.com/trevordevore/5eaa7333841d15f5bbbde490636dc143 Usage: `put htmlTextToMarkdown(htmltext of fld 1)` -- Trevor DeVore ScreenSteps www.screensteps.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Markdown ultra-lite
Alex wrote > a trailing "*" in a URL would > be converted to make the link open in a new browser tab/window - by > changing it to? TARGET="_blank" Couldn’t you simply replace your suitably chosen trailing characters with TARGET="_blank" after using the function? (I mention characters as a single * might be used elsewhere.) James ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Markdown ultra-lite
Well, just for completeness, I'll report that I have decided to use my own simple-minded version rather than mergMarkdownToXHTML. I had added one tiny convenience feature (a trailing "*" in a URL would be converted to make the link open in a new browser tab/window - by changing it to TARGET="_blank" ) to make it easier for my 'authors' to get it right. Turns out this isn't *just* a convenience - regular Markdown has *no way* to specify a link that opens in a new tab. In fact, Markdown doesn't allow spaces in the URI, so you can't even type it out longhand. Since many, or even most, of the links in articles on my site will want to open in new tabs, it's out of the question to do without that - so mergMarkdownToXHTML isn't going to work. So - I'm back to my own converter which will undoubtedly get a few more features added in the next week or so, so I'll post the final version (or a link to it) when I think I'm done. -- Alex. On 05/11/2017 20:40, Kay C Lan via use-livecode wrote: On Sun, Nov 5, 2017 at 1:39 AM, Alex Tweedly via use-livecode wrote: (*) I read about Markdown; it was interesting; I learned something - no hours were truly "wasted" Nor was I aware that mergMardownToXHMTL existed, so thank you for raising this thread so James could enlighten us. Now all I need is someone to tell me there is similar function that converts HTML (or more specifically the LC subset of HTML used by Fields) to Markdown otherwise I too will be reading more about Markdown (thanks for the link) and learning something new. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Markdown ultra-lite
On Sun, Nov 5, 2017 at 1:39 AM, Alex Tweedly via use-livecode wrote: > > (*) I read about Markdown; it was interesting; I learned something - no > hours were truly "wasted" > Nor was I aware that mergMardownToXHMTL existed, so thank you for raising this thread so James could enlighten us. Now all I need is someone to tell me there is similar function that converts HTML (or more specifically the LC subset of HTML used by Fields) to Markdown otherwise I too will be reading more about Markdown (thanks for the link) and learning something new. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Markdown ultra-lite
On 04/11/2017 13:21, James At The Hale via use-livecode wrote: You are aware of mergMarkdownToXHTML function from the mergmarkdown library, no? In a word: "No." :-( In a sentence: No, of course not; if I had known Monte had already done this in a thorough way, I wouldn't have wasted (*) a couple of hours doing the small, easy part of it I did. In a paragraph: No, had no idea. I did search both via Google (found references to using shell, didn't see one to margMarkdown, though that may be might due to my short attention span). and in the dictionary (which should have found it, so I suspect I searched for "narkdown" or some similar stupidity. (*) I read about Markdown; it was interesting; I learned something - no hours were truly "wasted" But - Thank you very much for pointing me in the right direction. Alex. When I was writing the code to format the description part of the docs (for the Dash docset stack) I was reminded by Monte (I think) of this. It works really well. James ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Markdown ultra-lite
You are aware of mergMarkdownToXHTML function from the mergmarkdown library, no? When I was writing the code to format the description part of the docs (for the Dash docset stack) I was reminded by Monte (I think) of this. It works really well. James ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Markdown ultra-lite
I wanted to find a LC implementation of markdown, so I could easily use markdown files on a website, and have them be converted to html for output. I really wanted it completely in LC, so I could just include it without worrying about installing, or checking for, any other languages, scripts, etc. But I could find one, so I thought I might try implementing it myself. Didn't take long to find a current version in Python (easier for me to convert than C or Perl :-) - but heavens there's a lot of code there !! And indeed when you read a description (try http://spec.commonmark.org/0.28/ for example) you can easily see why it's complicated to do full implementation. And, sadly, many of those complications could have been avoided, but weren't due to historical misfortune :-) So I have done an ultra-light version Restrictions and limitations: --- Links are only 'inline', not 'reference'. - the whole inline link must be on a single input line. - no autolink, HTML Tags or codespans to confuse them :-) - no checks on brackets within the link text - simple cases should just work, others won't Images are inline only, not referenced. - whole image spec must be on a single input line - doesn't do anything to deal with links within image description (mostly because I couldn't figure out what this part of the spec was trying to allow :-) NB - because images are done before links, it is possible to handle the common case where the inline image is withing the linktext - i.e. you can click on the image to go to the other URL, e.g. Here is a [picture ![some alt text](x.png) used within link](/images/bigx.png) Only one style of header is handled - using multiple '#'s rather than pseudo-underline. Emphasis, and everything else, isn't done - and may or may not be depending on whether I decide I car about it. - Additions and oddities : 1. If the last char in the URL is a '*' then it becomes a "new tab" link (i.e. TARGET='_blank'). 2. I added special handling for facebook links - see the code In case anyone else finds it useful, here's the code I'll figure out Github etc. and put it up there some day - but for now it's short enough I'm just going to include it here. It uses a couple of utility functions which are included. -- Alex. local sSubstitutions function markdownToHTML pMD put empty into sSubstitutions repeat for each line L in pMD -- first extract any image specs put L into LL put 1 into N repeat forever if decompose2(LL, "![", "](", p1, p2, p3) then if decompose1(p3, ")", p3a, p4) then put "" into sSubstitutions[N] put p1 & numtochar(N) & p4 into LL add 1 to N next repeat end if end if exit repeat end repeat -- and then do any links repeat forever if decompose2(LL, "[", "](", p1, p2, p3) then if decompose1(p3, ")", p3a, p4) then if char -1 of p3a = "*" then put "' TARGET='_blank" into char -1 of p3a end if if p2 = "fb" then put p1 & "class='icon fa-facebook' TARGET='_blank'>" & "" & p4 into LL else put p1 & "" & p2 & "" & p4 into LL end if next repeat end if end if exit repeat end repeat repeat with i = 1 to N replace numtochar(i) with sSubstitutions[i] in LL end repeat if LL is empty then put L into LL if LL is empty then put CR after tResult else put word 1 of LL into W replace "#" with empty in W if W is empty then put the number of chars in word 1 of LL into N put "" & word 2 to -1 of LL & "" into LL end if put LL &CR after tResult end if -- if NOT (tResult ends with CR) then exit repeat -- delete char -1 of tResult end repeat replace (numtochar(13) & numtochar(10)) with CR in tResult replace (CR & CR &CR) with (CR & "" & CR) in tResult replace (CR & CR) with (CR & "") in tResult return tResult end markdownToHTML function decompose1 pIn, pSep1, @p1, @p2 -- if the input string (pIn) contains the delimiter string (pSep1) then -- return TRUE and set the result variables to the parts 'before' and 'after' the delimiter -- else -- return FALSE, and leave p1, p2 unchanged put offset(pSep1, pIn) into t1 if t1 > 0 then put char 1 to t1-1 of pIn into p1 put char (t1+the number of chars in pSep1) to -1 of pIn into p2 return TRUE end if return FALSE end decompose1 function decompose2 pIn, pSep1, pSep2, @p1, @p2, @p3 -- if the input string (pIn) contains the (non-overlapping) delimiter strings (pSep1, pSep2) then -- return TRUE