Hello! Today i want to propose a couple Markdown extensions that could be added to Swift-Markdown and Swift-DocC.
As the Swift book (TSPL) is getting converted to use Swift-DocC, it’s become apparent that there are some markup features that it requires that Swift-DocC currently doesn’t have. The one i’m looking at today is the little “opt” suffix in the grammar sections in the Reference:
The Markdown parser currently in use (swift-cmark
, a fork of cmark-gfm
) doesn’t have a syntax for subscripts like this, and i’d like to add it. Late last year, i messed around with adding a superscript extension that used Reddit’s syntax (thanks to Christian Selig who i was chatting with at the time, for the nerd-snipe): word^superscript
or word^(superscript multiple words)
. This is a fairly popular syntax for writing superscripts in Markdown, as several different implementations have syntax much like this. (An alternative would be to use something like Pandoc’s syntax, which wraps the span in carets: word^superscript^
or word^superscript multiple words^
.)
Finding a common syntax for subscripts is somewhat harder, though: There are far fewer implementations of subscript syntax, and the common thread uses surrounding tildes: word~subscript~
. However, this currently clashes with GitHub’s “strikethrough” extension, which also uses surrounding tildes. This ambiguity can be solved by requiring two tildes instead of one, but for the moment Swift-DocC doesn’t do this, so both syntaxes are accepted: word ~stricken~
and word ~~stricken~~
.
A way to mitigate the syntax clash is to actually tweak the syntax to appear more like Reddit’s superscript, i.e. word~subscript
or word~(subscripting multiple words)
. This syntax doesn’t seem to have precedent anywhere that i could find, but it also doesn’t clash with GitHub’s strikethrough extension at all, which puts it at an advantage compared to Pandoc’s syntax, written above.
Summary of questions
To summarize the post:
- Can/should Swift-DocC adopt Reddit’s superscript syntax (
word^superscript
andword^(superscript)
)? This has an open PR on swift-cmark and could be integrated into Swift-DocC relatively easily. - Can/should Swift-DocC adopt its own subscript syntax, based on Reddit’s superscript syntax (
word~subscript
andword~(subscript)
)? This would be relatively easy to implement, based on the existing work for superscripts. - Can/should the subscript extension automatically require two tildes to use strikethrough (
plain ~~stricken~~
but notplain ~stricken~
)? Would this break anyone’s existing documentation? - Can/should Swift-DocC adopt Pandoc’s superscript and subscript syntax instead of Reddit’s (
word^superscript^
andword~subscript~
)? This would require forcing two tildes for strikethrough, which may break existing documentation.
All of the above references to Swift-DocC also apply to Swift-Markdown and swift-cmark, where the integration would be written to begin with.