Skip to content

Commit

Permalink
implemented jgm#168 according to new specification
Browse files Browse the repository at this point in the history
- added attributes so side-tracked syntax
- added test-cases
  • Loading branch information
Drezil committed Sep 11, 2017
1 parent d13d051 commit f0ba3a1
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/Text/Pandoc/Readers/Markdown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,8 @@ birdTrackLine c = try $ do
char c
-- allow html tags on left margin:
when (c == '<') $ notFollowedBy letter
-- allow inplace-images on left margin:
when (c == '!') $ notFollowedBy (char '[')
anyLine

--
Expand Down Expand Up @@ -782,28 +784,35 @@ blockQuote = do

openingDiv :: PandocMonad m => MarkdownParser m Attr
openingDiv = do
string "; ---"
string ":::"
skipMany (char ':')
skipMany spaceChar
string "div"
mclass <- optionMaybe $ do
c <- many1 alphaNum
skipMany1 spaceChar
skipMany1 (char ':')
return c
attr' <- option nullAttr $ do
skipMany spaceChar
attributes
let addClass :: Attr -> String -> Attr
addClass (id',cs, kv) c = (id', (c:cs), kv)
anyLine
return attr'
return $ maybe attr' (addClass attr') mclass -- if we have mclass, add it, otherwise leave it unchanged

closingDiv :: PandocMonad m => MarkdownParser m ()
closingDiv = do
string "; ---"
string ":::"
skipMany spaceChar
((char '\n' >> return ()) <|> eof)

divBlockBirdTrack :: PandocMonad m => MarkdownParser m (F Blocks)
divBlockBirdTrack = try $ do
pos <- getPosition
when (sourceColumn pos /= 1) $ fail "Not in first colum"
attr' <- openingDiv
lns <- many1 $ birdTrackLine ';'
-- if (as is normal) there is always a space after ;, drop it
attr' <- option nullAttr (attributes <* (skipSpaces >> newline))
lns <- many1 $ birdTrackLine '!'
-- if (as is normal) there is always a space after !, drop it
let lns' = if all (\ln -> null ln || take 1 ln == " ") lns
then map (drop 1) lns
else lns
Expand Down
87 changes: 87 additions & 0 deletions test/command/168.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@

```
% pandoc -f markdown -t html
:::{.class}
foo
:::
^D
<div class="class">
foo
</div>
```

```
% pandoc -f markdown -t html
:::::: info ::
foo
:::
^D
<div class="info">
foo
</div>
```

```
% pandoc -f markdown -t html
:::::: info :: {.combine}
foo
:::
^D
<div class="info combine">
foo
</div>
```

```
% pandoc -f markdown -t html
:::::: {#id .class}
foo
:::
^D
<div id="id" class="class">
foo
</div>
```

```
% pandoc -f markdown -t html
{#id .class}
! foo
^D
<div id="id" class="class">
foo
</div>
```

```
% pandoc -f markdown -t html
! foo
!
! {.attr}
! ! nested
^D
<div>
<p>foo</p>
<div class="attr">
nested
</div>
</div>
```

```
% pandoc -f markdown -t html
!noimage
^D
<div>
noimage
</div>
```

```
% pandoc -f markdown -t html
![](foo)
^D
<figure>
<img src="foo" />
</figure>
```

0 comments on commit f0ba3a1

Please sign in to comment.