Replies: 6 comments 10 replies
-
Liking what you got so far…will go through in more detail soon :-) |
Beta Was this translation helpful? Give feedback.
-
nice list! more here https://dev.to/swyx/6-things-markdown-got-wrong-124 eg i think headers should always always slugify and autogenerate their own #anchors. i still feel like intermixing html in markdown in html is too much effort and unpredictable, i wonder if theres a way to add some rules that would make it easier. i would love an vs awhen i use |
Beta Was this translation helpful? Give feedback.
-
For handling generic directives, I feel that they will need to be implemented as functions taking an AST node and returning an AST node-or-nodes that would be substituted for the original. #52 (comment), for example, could be implemented with something like this: const config = {
directives: {
container_block: {
sample(content) {
const codeBlock = new_markdown_block('```', content);
const rendered = content;
return [ ...codeBlock, ...rendered ];
}
}
}
} An empty array would, of course, end up removing the directive from the output (could be used to conditionally include sections based on various factors). And perhaps for convenience, a non-array object would be considered a single AST node. The drawback to writing them as AST-to-AST transformation functions is that then you have to make the AST API available for library users to import in their config, somehow. Perhaps for convenience, returning a string would count that string as Markdown to be parsed? E.g.: const config = {
directives: {
container_block: {
sample(content) {
let mdContent = content.asMarkdownString();
if (! mdContent.endsWith('\n')) mdContent = `${mdContent}\n`;
const codeBlock = '```\n' + mdContent + '```\n';
const rendered = mdContent;
return `${codeBlock}${rendered}`;
}
}
}
} Not sure if either of those ideas is a good one; I'm mostly just spitballing here. I am sure, though, that the output of a generic directive needs to be Markdown (whether as an AST or as a string), rather than HTML. Because as you say, Markdown is not exclusively a compile-to-HTML language. |
Beta Was this translation helpful? Give feedback.
-
I like this a lot. Lovely details and directives are exciting. I consider myself a frustrated Markdown user and this addresses most of my complaints. (happy aquatic bird flapping noises) Any thoughts on contentless directives? (the linked proposal says it "may" be followed with content but there's no example without) Thinking of an emoji replacement usecase, so this: how much time? :emoji[turtle] :emoji[rabbit] could hypothetically be shortened to: how much time? :turtle :rabbit If not, then this would also work: how much time? :turtle[] :rabbit[] For directive attributes, double square brackets seem unsurprising but idk: :reminder[check the thing][when=tomorrow] Directives are really intriguing. I'm not sure this is the best usecase, but here's a poll example that comes to mind: :::poll
What is your preferred stimulant?
- caffeine
- social media
- healthy living
- an exquisite flavour of markdown
::: Wondering if that would transform into something functionally like this: <Poll
prompt="What is your preferred stimulant?"
options={['caffeine', 'social media', 'healthy living', 'an exquisite flavour of markdown']}
id="maybe_a_generated_id_or_something"
/> Makes me wonder about the tradeoffs between directives and components. |
Beta Was this translation helpful? Give feedback.
-
Hey @pngwn , I hope you're doing well! |
Beta Was this translation helpful? Give feedback.
-
Thanks for the well thought out points: many times when I'm struggling with edge behavior working with a particular dialect of markdown I often come back to this post and there is a salient note on my problem here. And now that John MacFarlane himself has tried to address the issues around markdown with djot, will be interesting to hear if you have any thoughts on potentially using that |
Beta Was this translation helpful? Give feedback.
-
In #259 I alluded to other changes in v1, besides the configuration API. The biggest one is something that has been one of my biggest frustration in some regards: markdown itself. Now, lets get this out of the way: markdown is excellent and easily the best document markup format we have ever had. Kudos to Mr Gruber and all who have pushed markdown forward. Nothing in this document should be considered a derogation of markdown, I have nothing but respect and admiration for everything that has brought us to this point. This is a criticism, in many ways, but hopefully a constructive one. It is also just the opinion of a single penguin, and a penguin of questionable character, at that.
Penguin-flavoured markdown
Link to easier to navigate gist.
Context
This document is an early suggestion of what markdown in mdsvex might look like (it will also exist as a standalone markdown flavour—yes, another one), but it takes a slightly different approach, removing features, as well as adding them. I still feel as though it can be considered 'markdown' in spirit (a 'suberset' that shares most of the syntax and semantics), although technically that probably isn't true.
Over the past few months I have been doing a lot of reading and research around markdown, the various flavours, and the history. I have read the CommonMark spec more times that I wish to think about, I have thousands of words of notes. I have also looked very deeply into various markdown flavours (GitHub Flavoured Markdown, Markdown Extra, R Markdown, MultiMarkdown) (and others), as well as other document markup formats (reStructured text, AsciiDoc(tor), textile, text2tags, org mode, setext). Some of these formats are almost 3 decades old, and at this stage I have learned more than I ever wished to know about human-readable document markup formats and their history, but honestly learning about the history and evolution of this ecosystem has been very rewarding and I bow down to all of those who have played a part; it is thanks to them that we have such a rich set of tools and such a vibrant ecosystem.
This document uses CommonMark as the baseline (not Gruber's original 'spec'), all markdown variants are considered just that. Many of the older formats would be too much of a break from what folk are used to today but learning about them was interesting and provided useful context.
This document will detail a list of differences from markdown. The aim is to remove ambiguity (by removing, restricting or modifying syntax) and add some essential features out of box (via a few syntax additions).
On reducing ambiguity, I have to give all of the credit to John MacFarlane, he is smarter than I am and I have stolen his ideas, mainly from here
Principles
Some over-arching principle. Things that I believe to be true. Some will disagree but these are some of the key guiding principles that guide what I'm about to suggest. There are always exceptions but i generally find these things to hold true.
Indentation
Indentation ins markdown creates code blocks or literal/ verbatim text. This is naturally problematic for mdsvex (when mixing HTML and markdown you may want to indent for clarity) but it also introduces confusing rules around when certain markdown syntax will render a code block and when it will do nothing. Indented code blocks arguably violate the invisible syntax principle but definitely violate the 'more than one way to do things' principle because fenced code blocks exist.
Fenced code blocks exist and are generally more useful. They allow you to include a variety of useful metadata.
PFM will remove the significance from indentation.
Link references
In markdown you can do this, it is quite explicit and very useful:
But you can also do this:
The problem is, we don't know if the second one is a shorthand link until we discover the link reference definition. This is complex for parsers but I also think it is confusing for humans, there is a degree of context switching that is required by jumping around a document to search for the possible link reference definition. If no definition is found then this is actually just a normal paragraph:
<p>[link_text_and_ref]</p>
.PFM will require shorthand link references to be explicit, the shape of the syntax alone will dictate its nature:
Headings
These are all valid headings:
The first two are
setext
style headings and are confusing especially when they are near to horizontal rules, the others areatx
style. These styles are named after the language they were borrowed from. All but one of these will be removed.Leading octothorpes will distinguish headings, nothing else will be supported, trailing octothorpes will be considered part of the heading text:
Lists
Lists with strange numbers will be supported because it seems sensible, the auto-heading functionality of markdown is very confusing:
Emphasis
There is no single feature in markdown that is as confusing as emphasis. The markdown spec as 17 rules for emphasis, each more confusing than the last. That is seventeen. This ambiguity is mainly due to the fact that there are many wasy to emphasise and strongly emphasise text. You can read more here
What is this:
or this:
(I'm not sure GitHub is rendering these in accordance with the commonmark spec).
As you can see, it gets confusing fast. Intraword emphasis is even more confusing.
PFM will have distinct syntax for emphasis and strong emphasis. This is a hard break from the spec but a necessary one. Intraword emphasis is very rare but needs to be supported. Distinct syntax will be used for that case.
Line breaks
Line breaks come in a few forms, hard and soft.
Lets do a small experiment, should these two paragraphs render the same?
They don't:
The second paragraph actually had two space characters after the work "hello" this made it a hard line break. The first is a 'soft' line break (it basically renders in HTML as if there is no line break), the second is a 'hard' line break and will render a
br
for times when line breaks add semantic meaning (poems, addresses).I personally find invisible syntax quite hard to see. Markdown has an explicit version too:
hello friends hello\ friends
PFM will support both hard and soft breaks, hard breaks will only be supported via the explicit backslash syntax.
Superscript
Superscript is not part of the markdown spec, PFM will support it via a pair of
^
characters (rules TBD):Will render:
Subscript
Superscript is not part of the markdown spec, PFM will support it via a pair of
^
characters (rules TBD):Will render:
Strikethrough
Strikethrough is not supported by markdown but I'd like to support them in PFM. They will match common syntax for strikethrough
~~word~~
. Undecided on intraword strikethrough but it is simpler than emphasis.Some options:
Tables
Here we go. I think tables are a critical feature and i haven't really worked this one out yet. It is very complex and there are a million edge cases. The basis should be GFM pipe tables but I'd like the ability to have headings on left, in addition to or instead of across the top, as well as the ability to merge cells (at least horizontally but probably both). I was thinking something like this:
This looks weird and will almost definitely not work but it is a start. It may be better to have distinct syntax for simple pip tables (GFM style) and more complex tables with more explicit syntax, this does violate a principle though. Needs more thought.
Generic directives
This one is a bit left of field, but I think it is very important. Markdown needs a way for users to 'plugin' with a generic syntax that covers most usecases. This essentially brings wordpress/ hugo style 'shortcodes' into the spec, except it is more flexible and more powerful. This feature has been co-opted from here.
It is powerful and flexible due the different forms.
Inline:
Would be accompanied by a function. API TBD, realistically this would be a custom AST compile handler (becaue this would have its own AST node type with the necessary info in it) rather than the below but this is illustrative:
Leaf block (block, cannot be inside inline content; leaf, cannot have children):
Similar function as above to render a youtube video.
Container block (block, cannot be inside inline content content; container, can have children):
The linked proposal also suggest
{key=val}
for 'attributes' but{
and}
are sacred in mdsvex and not viable for markdown syntax. I think the capability to pass props would be nice (::youtube[title]{start=180}
for example) but I'm not sure what that syntax should look like.What is really great about the generic directive proposal is that it can actually replace a lot of other github extensions (it could actually be used for addition, delete, etc. from above), as well as allowing easy customisation. It is very, very powerful, in my opinion. PFM will support it by default.
This is where i am up to. Please feed me back!
Edit: Replaced 'Additions and deletions' with 'Strikethrough'. Update syntax to use
~~word~~
.Beta Was this translation helpful? Give feedback.
All reactions