Skip to content

Commit

Permalink
AsciiDoc writer: Fixed code blocks.
Browse files Browse the repository at this point in the history
Closes #1861.
  • Loading branch information
jgm committed Nov 24, 2015
1 parent 4361dc0 commit b20ecbe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
13 changes: 6 additions & 7 deletions src/Text/Pandoc/Writers/AsciiDoc.hs
Expand Up @@ -160,13 +160,12 @@ blockToAsciiDoc opts (Header level (ident,_,_) inlines) = do
_ -> empty) <> blankline
else
identifier $$ text (replicate level '=') <> space <> contents <> blankline)
blockToAsciiDoc _ (CodeBlock (_,classes,_) str) = return $
flush (attrs <> dashes <> space <> attrs <> cr <> text str <>
cr <> dashes) <> blankline
where dashes = text $ replicate (maximum $ map length $ lines str) '-'
attrs = if null classes
then empty
else text $ intercalate "," $ "code" : classes
blockToAsciiDoc _ (CodeBlock (_,classes,_) str) = return $ (flush $
if null classes
then "...." $$ text str $$ "...."
else attrs $$ "----" $$ text str $$ "----")
<> blankline
where attrs = "[" <> text (intercalate "," ("source" : classes)) <> "]"
blockToAsciiDoc opts (BlockQuote blocks) = do
contents <- blockListToAsciiDoc opts blocks
let isBlock (BlockQuote _) = True
Expand Down
40 changes: 20 additions & 20 deletions tests/writer.asciidoc
Expand Up @@ -80,11 +80,11 @@ ______________________
--
Code in a block quote:
--------------------
....
sub status {
print "working";
}
--------------------
....
A list:
Expand Down Expand Up @@ -116,23 +116,23 @@ Code Blocks

Code:

--------------------------------------
....
---- (should be four hyphens)
sub status {
print "working";
}
this code block is indented by one tab
--------------------------------------
....

And:

--------------------------------------------
....
this code block is indented by two tabs
These should not be escaped: \$ \\ \> \[ \{
--------------------------------------------
....

'''''

Expand Down Expand Up @@ -325,9 +325,9 @@ _apple_::
_orange_::
orange fruit
+
---------------------
....
{ orange code block }
---------------------
....
+
__________________
orange block quote
Expand Down Expand Up @@ -393,17 +393,17 @@ foo
This should be a code block, though:
-------
....
<div>
foo
</div>
-------
....
As should this:
--------------
....
<div>foo</div>
--------------
....
Now, nested:
Expand All @@ -415,17 +415,17 @@ Multiline:
Code block:
----------------
....
<!-- Comment -->
----------------
....
Just plain comment, with trailing spaces on the line:
Code:
------
....
<hr />
------
....
Hr’s:
Expand Down Expand Up @@ -616,9 +616,9 @@ Indented link:/url[thrice].

This should [not][] be a link.

-----------
....
[not]: /url
-----------
....

Foo link:/url/[bar].

Expand Down Expand Up @@ -654,9 +654,9 @@ ________________________________

Auto-links should not occur here: `<http://example.com/>`

------------------------------
....
or here: <http://example.com/>
------------------------------
....

'''''

Expand Down

0 comments on commit b20ecbe

Please sign in to comment.