Skip to content

Commit

Permalink
Merge pull request #68 from Omikhleia/fix-pandoc-like-attributes
Browse files Browse the repository at this point in the history
fix: Pandoc-like attributes are too restrictive
  • Loading branch information
Witiko authored Aug 25, 2023
2 parents 104d7fa + e1a4286 commit 8e8c309
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions lunamark/reader/markdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,30 @@ parsers.indented_blocks = function(bl)
end

-- Attributes list as in Pandoc {#id .class .class-other key=value key2="value 2"}
parsers.identifier = parsers.letter
* (parsers.alphanumeric + S("_-"))^0
parsers.attrvalue = (parsers.dquote * C((parsers.alphanumeric + S("._- "))^1) * parsers.dquote)
+ C((parsers.alphanumeric + S("._-"))^1)

parsers.attrpair = Cg(C((parsers.identifier)^1)
-- Note: Pandoc has the same identifier definitions, but its interpretation
-- of a letter (and by extension an alphanumeric value) extends to alphabetic
-- *Unicode* characters.
parsers.attrid = parsers.letter
* (parsers.alphanumeric + S("_-:."))^0

parsers.attrvalue = (parsers.dquote
* C((parsers.anyescaped - parsers.dquote)^0)
* parsers.dquote)
+ (parsers.squote
* C((parsers.anyescaped - parsers.squote)^0)
* parsers.squote)
+ C((parsers.anyescaped - parsers.dquote - parsers.space - P("}"))^1)

parsers.attrpair = Cg(C(parsers.attrid)
* parsers.optionalspace * parsers.equal * parsers.optionalspace
* parsers.attrvalue)
* parsers.optionalspace^-1
parsers.attrlist = Cf(Ct("") * parsers.attrpair^0, rawset)

parsers.class = (P("-") * Cc("unnumbered")) + (parsers.period * C((parsers.identifier)^1))
parsers.class = (P("-") * Cc("unnumbered")) + (parsers.period * C((parsers.attrid)^1))
parsers.classes = (parsers.class * parsers.optionalspace)^0

parsers.hashid = parsers.hash * C((parsers.identifier)^1)
parsers.hashid = parsers.hash * C((parsers.alphanumeric + S("-_:."))^1)

parsers.attributes = P("{") * parsers.optionalspace
* Cg(parsers.hashid^-1) * parsers.optionalspace
Expand All @@ -176,7 +185,8 @@ parsers.attributes = P("{") * parsers.optionalspace
return attr
end
-- Raw attributes similar to Pandoc (=format key=value key2="value 2")
parsers.raw = parsers.equal * C((parsers.identifier)^1) * parsers.optionalspace
parsers.rawid = parsers.alphanumeric + S("_-")
parsers.raw = parsers.equal * C((parsers.rawid)^1) * parsers.optionalspace
parsers.rawattributes = P("{") * parsers.optionalspace
* parsers.raw * Cg(parsers.attrlist)
* parsers.optionalspace * P("}")
Expand Down

0 comments on commit 8e8c309

Please sign in to comment.