Markdown library?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Markdown library?
Hi all,
just checking if anyone is aware of a markdown library for formatting text in a LiveCode field?
I couldn't find one, so I'm guessing not, but maybe I missed it?
Many thanks
Stam
just checking if anyone is aware of a markdown library for formatting text in a LiveCode field?
I couldn't find one, so I'm guessing not, but maybe I missed it?
Many thanks
Stam
Re: Markdown library?
Stam.
What is a markDown library? A table of some sort that relates text properties to this or that?
Craig
What is a markDown library? A table of some sort that relates text properties to this or that?
Craig
Re: Markdown library?
markdown is a shorthand way of generating formatted text, typically used instead of html as it's less intrusive of the text provided.
For example, and <H1> header and some styles would be
instead of
It just means you can write plain text with a few notations that are unobtrusive and it can be rendered in "proper" HTML.
Things like lists become a lot easier: instead of
There's a ton of references to this online (and it's the defacto way of formatting GitHub documents).
Here's a simple reference: https://www.markdownguide.org/basic-syntax/
I guess a simple library wouldn't be enough, as you'd need a mode where the field produces the plain text with markdown notation and a different mode to show the rendered text.
But should be doable... so just wondering if someone might have already made the effort...
For example, and <H1> header and some styles would be
Code: Select all
# This is a header
This word is in **bold**
This word is *italic*
Code: Select all
<H1>This is a header</H1>
This word is in <b>bold</b>
This word is <em>italic</em>
Things like lists become a lot easier:
Code: Select all
- First item
- Second item
- Third item
- Indented item
- Indented item
- Fourth item
Code: Select all
<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item
<ul>
<li>Indented item</li>
<li>Indented item</li>
</ul>
</li>
<li>Fourth item</li>
</ul>
Here's a simple reference: https://www.markdownguide.org/basic-syntax/
I guess a simple library wouldn't be enough, as you'd need a mode where the field produces the plain text with markdown notation and a different mode to show the rendered text.
But should be doable... so just wondering if someone might have already made the effort...
Re: Markdown library?
Take a look at @trevordevore's gist and if you think it's useful, give him a star. 
LiveCode Markdown converter: https://gist.github.com/trevordevore/5090459

LiveCode Markdown converter: https://gist.github.com/trevordevore/5090459
Be kind, we all have our own wars.
https://torocruzand.com/
https://torocruzand.com/
-
- Livecode Opensource Backer
- Posts: 10076
- Joined: Fri Feb 19, 2010 10:17 am
Re: Markdown library?
I am not sure about that, as a 'standard' text import would bring plain text with markdown notation into a text field.I guess a simple library wouldn't be enough, as you'd need a mode where the field produces the plain text with markdown notation and a different mode to show the rendered text.
What would then be needed is a script (in, say, a button) to make that show up in another text field as rendered text.
Any script would "just' have to pop the text from the source file into a variable and "chew" its way along it through a load of conditional loops.
https://daringfireball.net/projects/markdown/
I went here: https://www.markdownguide.org/getting-started/
This made me feel a bit queer:
"One of the most confusing aspects of using Markdown is that practically every Markdown application implements a slightly different version of Markdown. These variants of Markdown are commonly referred to as flavors. It’s your job to master whatever flavor of Markdown your application has implemented."
I went here: https://macdown.uranusjr.com/
because I am currently working on a MacOS 12 iMac.
-
- Livecode Opensource Backer
- Posts: 10076
- Joined: Fri Feb 19, 2010 10:17 am
Re: Markdown library?
The first thing I learnt (accidently) is that is you bung a '-' followed by a space in front of some text you end up with a 'bullet':
- - -
The ONLY problem about a script parsing this sort of thing would be HOW to differentiate between "Richmond's trans - sexual cousin" and "- transsexualism" where the second one is formatting for a bullet, and the second one is my personal problem, so were one looking for a "-" as a formatting mark one would have to look for a "-" preceded by a carriage return.
- - -
The ONLY problem about a script parsing this sort of thing would be HOW to differentiate between "Richmond's trans - sexual cousin" and "- transsexualism" where the second one is formatting for a bullet, and the second one is my personal problem, so were one looking for a "-" as a formatting mark one would have to look for a "-" preceded by a carriage return.
-
- Livecode Opensource Backer
- Posts: 10076
- Joined: Fri Feb 19, 2010 10:17 am
Re: Markdown library?
And an underscore preceding a phrase followed by another underscore results in italicisation:
- - -
So, if you have the patience (and that is all it should take as this is not rocket science) you should be able to knock together a markdown decoder without too much difficulty.
- - -
So, if you have the patience (and that is all it should take as this is not rocket science) you should be able to knock together a markdown decoder without too much difficulty.
-
- Livecode Opensource Backer
- Posts: 10076
- Joined: Fri Feb 19, 2010 10:17 am
Re: Markdown library?
And so it goes:
- - -
And this was all that I required:
https://daringfireball.net/projects/markdown/syntax
- - -
And this was all that I required:
https://daringfireball.net/projects/markdown/syntax
-
- Livecode Opensource Backer
- Posts: 10076
- Joined: Fri Feb 19, 2010 10:17 am
Re: Markdown library?
Looking at markdown (which resembles HTML in some ways: all a bit confusing) I cannot help thinking a lot of things are redundant:
<table>
<tr>
<td>Let me introduce myself.</td>
<tr>
<table>
to produce:
- -
Seems clunky when, surely:
<table>Let me introduce myself.</table>
should suffice?
<table>
<tr>
<td>Let me introduce myself.</td>
<tr>
<table>
to produce:
- -
Seems clunky when, surely:
<table>Let me introduce myself.</table>
should suffice?
Re: Markdown library?
That's exactly what I was looking for, thank you @andresdt!andresdt wrote: ↑Mon Jul 08, 2024 2:59 pmTake a look at @trevordevore's gist and if you think it's useful, give him a star.
LiveCode Markdown converter: https://gist.github.com/trevordevore/5090459
Haven't tested it yet, but I'm sure it will work fine (he says

-
- VIP Livecode Opensource Backer
- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Markdown library?
Good find, thank you.andresdt wrote: ↑Mon Jul 08, 2024 2:59 pmTake a look at @trevordevore's gist and if you think it's useful, give him a star.
LiveCode Markdown converter: https://gist.github.com/trevordevore/5090459
That library is described as "Converts a styledText array to Markdown".
Do you know of a library that goes the other way, converting Markdown to LC styledText arrays or htmlText?
I wrote an incomplete one about 20 years ago for a project, but Markdown has grown so much over the years and most other languages have lots of tools for these things, so hopefully our community does too.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Markdown library?
The first section you post is html. It's not markdown.richmond62 wrote: ↑Mon Jul 08, 2024 6:05 pmLooking at markdown (which resembles HTML in some ways: all a bit confusing) I cannot help thinking a lot of things are redundant:
<table>
<tr>
<td>Let me introduce myself.</td>
<tr>
<table>
A typical markdown interpreter to produce the same result would take this as the text:
Code: Select all
|Let me introduce myself.|
|------------------------| // just 3 dashes needed to signify a row, these do not need to line up
if you're happy using malformed HTML sure. But as soon as you add anything else to the 'table' you'll have to do a large amount of work to make it function.
Markdown tables are much simpler than HTML tables and take the form:
Code: Select all
| column 1 header | column 2 header|
|-----------------|----------------|
| cell 1 | cell 2 |
EDIT: This is the GitHub flavour of markdown - John Gruber's initial creation does not include this functionality, but many flavours do
If you want to see what markdown tables look like have a look a wiki I'm creating on GitHub: https://github.com/stam66/regexPrimerFo ... characters
This is part of an intro to regex for LiveCode users I started writing mainly to clear up some more apocryphal stuff in my head, but reckon it may be useful to other LiveCoders... it's not yet complete but it's mostly there. I'll announce it properly when it is.
I don't know if Trevor's gist caters for this type of thing, but worth looking at.
Last edited by stam on Mon Jul 08, 2024 6:56 pm, edited 1 time in total.
-
- Livecode Opensource Backer
- Posts: 10076
- Joined: Fri Feb 19, 2010 10:17 am
Re: Markdown library?
Not particularly, but I am learning from https://daringfireball.net/projects/markdown/basics, and this is what happens:if you're happy using malformed HTML sure
- -
Obviously my app (MacDown) does not differentiate between HTML and markdown, and doing this:
- -
Does NOT produce the same result.
Re: Markdown library?
Yes it does not. John Gruber was the initial inventor but in the last 20 years his format has been stagnant while many have added to this. I edited my post above to specifically mention that this is the GitHub dialect of markdown, and many, many markdown apps use this.
It's all shorthand for HTML - the underlying engine has to replace patterns and actually I see this as a potential role for regex.
Trevor's gist linked above coverts a styled text field's content to markdown and loops around 'style runs', it's not a full interpreter as it doesn't seem to do the opposite. A project for when I have more time maybe.
PS: I'm a long time fan of the daring fireball site. I bought some t-shirts to support them (pretty cool T's actually). One of the few RSS feeds I subscribe to.
But rather than using this antiquated reference, look at the opensource https://www.markdownguide.org
This is what is commonly used.