Merge pull request #1290 from tarleb/fix-header-params
Org reader: Fix block parameter reader, relax constraints
This commit is contained in:
commit
12d0dcffe8
2 changed files with 25 additions and 6 deletions
|
@ -318,7 +318,7 @@ blockHeaderStart :: OrgParser (Int, String)
|
||||||
blockHeaderStart = try $ (,) <$> indent <*> blockType
|
blockHeaderStart = try $ (,) <$> indent <*> blockType
|
||||||
where
|
where
|
||||||
indent = length <$> many spaceChar
|
indent = length <$> many spaceChar
|
||||||
blockType = map toLower <$> (stringAnyCase "#+begin_" *> many orgArgWordChar)
|
blockType = map toLower <$> (stringAnyCase "#+begin_" *> orgArgWord)
|
||||||
|
|
||||||
withRaw' :: (String -> F Blocks) -> BlockProperties -> OrgParser (F Blocks)
|
withRaw' :: (String -> F Blocks) -> BlockProperties -> OrgParser (F Blocks)
|
||||||
withRaw' f blockProp = (ignHeaders *> (f <$> rawBlockContent blockProp))
|
withRaw' f blockProp = (ignHeaders *> (f <$> rawBlockContent blockProp))
|
||||||
|
@ -422,16 +422,23 @@ rundocBlockClass :: String
|
||||||
rundocBlockClass = rundocPrefix ++ "block"
|
rundocBlockClass = rundocPrefix ++ "block"
|
||||||
|
|
||||||
blockOption :: OrgParser (String, String)
|
blockOption :: OrgParser (String, String)
|
||||||
blockOption = try $ (,) <$> orgArgKey <*> orgArgValue
|
blockOption = try $ (,) <$> orgArgKey <*> orgParamValue
|
||||||
|
|
||||||
|
inlineBlockOption :: OrgParser (String, String)
|
||||||
|
inlineBlockOption = try $ (,) <$> orgArgKey <*> orgInlineParamValue
|
||||||
|
|
||||||
orgArgKey :: OrgParser String
|
orgArgKey :: OrgParser String
|
||||||
orgArgKey = try $
|
orgArgKey = try $
|
||||||
skipSpaces *> char ':'
|
skipSpaces *> char ':'
|
||||||
*> many1 orgArgWordChar
|
*> many1 orgArgWordChar
|
||||||
|
|
||||||
orgArgValue :: OrgParser String
|
orgParamValue :: OrgParser String
|
||||||
orgArgValue = try $
|
orgParamValue = try $
|
||||||
skipSpaces *> many1 orgArgWordChar <* skipSpaces
|
skipSpaces *> many1 (noneOf "\t\n\r ") <* skipSpaces
|
||||||
|
|
||||||
|
orgInlineParamValue :: OrgParser String
|
||||||
|
orgInlineParamValue = try $
|
||||||
|
skipSpaces *> many1 (noneOf "\t\n\r ]") <* skipSpaces
|
||||||
|
|
||||||
orgArgWordChar :: OrgParser Char
|
orgArgWordChar :: OrgParser Char
|
||||||
orgArgWordChar = alphaNum <|> oneOf "-_"
|
orgArgWordChar = alphaNum <|> oneOf "-_"
|
||||||
|
@ -1067,7 +1074,7 @@ inlineCodeBlock :: OrgParser (F Inlines)
|
||||||
inlineCodeBlock = try $ do
|
inlineCodeBlock = try $ do
|
||||||
string "src_"
|
string "src_"
|
||||||
lang <- many1 orgArgWordChar
|
lang <- many1 orgArgWordChar
|
||||||
opts <- option [] $ enclosedByPair '[' ']' blockOption
|
opts <- option [] $ enclosedByPair '[' ']' inlineBlockOption
|
||||||
inlineCode <- enclosedByPair '{' '}' (noneOf "\n\r")
|
inlineCode <- enclosedByPair '{' '}' (noneOf "\n\r")
|
||||||
let attrClasses = [translateLang lang, rundocBlockClass]
|
let attrClasses = [translateLang lang, rundocBlockClass]
|
||||||
let attrKeyVal = map toRundocAttrib (("language", lang) : opts)
|
let attrKeyVal = map toRundocAttrib (("language", lang) : opts)
|
||||||
|
|
|
@ -929,5 +929,17 @@ tests =
|
||||||
, "#+end_html"
|
, "#+end_html"
|
||||||
] =?>
|
] =?>
|
||||||
rawBlock "html" "\n<span>boring</span>\n\n"
|
rawBlock "html" "\n<span>boring</span>\n\n"
|
||||||
|
|
||||||
|
, "Non-letter chars in source block parameters" =:
|
||||||
|
unlines [ "#+BEGIN_SRC C :tangle xxxx.c :city Zürich"
|
||||||
|
, "code body"
|
||||||
|
, "#+END_SRC"
|
||||||
|
] =?>
|
||||||
|
let classes = [ "c", "rundoc-block" ]
|
||||||
|
params = [ ("rundoc-language", "C")
|
||||||
|
, ("rundoc-tangle", "xxxx.c")
|
||||||
|
, ("rundoc-city", "Zürich")
|
||||||
|
]
|
||||||
|
in codeBlockWith ( "", classes, params) "code body\n"
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue