Jira writer: use noformat instead of code for unknown languages.

Code blocks that are not marked as a language supported by Jira are
rendered as preformatted text with `{noformat}` blocks.

Fixes: 
This commit is contained in:
Albert Krewinkel 2021-03-08 12:40:25 +01:00
parent efc9f4a762
commit eb184d9148
No known key found for this signature in database
GPG key ID: 388DC0B21F631124
3 changed files with 37 additions and 38 deletions
src/Text/Pandoc/Writers
test
Tests/Writers
writer.jira

View file

@ -126,13 +126,13 @@ toJiraCode :: PandocMonad m
-> Text -> Text
-> JiraConverter m [Jira.Block] -> JiraConverter m [Jira.Block]
toJiraCode (ident, classes, _attribs) code = do toJiraCode (ident, classes, _attribs) code = do
let lang = case find (\c -> T.toLower c `elem` knownLanguages) classes of
Nothing -> Jira.Language "java"
Just l -> Jira.Language l
let addAnchor b = if T.null ident let addAnchor b = if T.null ident
then b then b
else [Jira.Para (singleton (Jira.Anchor ident))] <> b else [Jira.Para (singleton (Jira.Anchor ident))] <> b
return . addAnchor . singleton $ Jira.Code lang mempty code return . addAnchor . singleton $
case find (\c -> T.toLower c `elem` knownLanguages) classes of
Nothing -> Jira.NoFormat mempty code
Just l -> Jira.Code (Jira.Language l) mempty code
-- | Creates a Jira definition list -- | Creates a Jira definition list
toJiraDefinitionList :: PandocMonad m toJiraDefinitionList :: PandocMonad m
@ -310,7 +310,7 @@ registerNotes contents = do
knownLanguages :: [Text] knownLanguages :: [Text]
knownLanguages = knownLanguages =
[ "actionscript", "ada", "applescript", "bash", "c", "c#", "c++" [ "actionscript", "ada", "applescript", "bash", "c", "c#", "c++"
, "css", "erlang", "go", "groovy", "haskell", "html", "javascript" , "css", "erlang", "go", "groovy", "haskell", "html", "java", "javascript"
, "json", "lua", "nyan", "objc", "perl", "php", "python", "r", "ruby" , "json", "lua", "nyan", "objc", "perl", "php", "python", "r", "ruby"
, "scala", "sql", "swift", "visualbasic", "xml", "yaml" , "scala", "sql", "swift", "visualbasic", "xml", "yaml"
] ]

View file

@ -68,5 +68,15 @@ tests =
spanWith ("unicorn", [], []) (str "Unicorn") =?> spanWith ("unicorn", [], []) (str "Unicorn") =?>
"{anchor:unicorn}Unicorn" "{anchor:unicorn}Unicorn"
] ]
, testGroup "code"
[ "code block with known language" =:
codeBlockWith ("", ["java"], []) "Book book = new Book(\"Algebra\")" =?>
"{code:java}\nBook book = new Book(\"Algebra\")\n{code}"
, "code block without language" =:
codeBlockWith ("", [], []) "preformatted\n text.\n" =?>
"{noformat}\npreformatted\n text.\n{noformat}"
]
] ]
] ]

View file

@ -33,11 +33,10 @@ bq. This is a block quote. It is pretty short.
{quote} {quote}
Code in a block quote: Code in a block quote:
{code:java} {noformat}
sub status { sub status {
print "working"; print "working";
} }{noformat}
{code}
A list: A list:
# item one # item one
@ -56,22 +55,20 @@ And a following paragraph.
h1. {anchor:code-blocks}Code Blocks h1. {anchor:code-blocks}Code Blocks
Code: Code:
{code:java} {noformat}
---- (should be four hyphens) ---- (should be four hyphens)
sub status { sub status {
print "working"; print "working";
} }
this code block is indented by one tab this code block is indented by one tab{noformat}
{code}
And: And:
{code:java} {noformat}
this code block is indented by two tabs this code block is indented by two tabs
These should not be escaped: \$ \\ \> \[ \{ These should not be escaped: \$ \\ \> \[ \{{noformat}
{code}
---- ----
h1. {anchor:lists}Lists h1. {anchor:lists}Lists
h2. {anchor:unordered}Unordered h2. {anchor:unordered}Unordered
@ -236,9 +233,8 @@ red fruit
contains seeds, crisp, pleasant to taste contains seeds, crisp, pleasant to taste
* *_orange_* * *_orange_*
orange fruit orange fruit
{code:java} {noformat}
{ orange code block } { orange code block }{noformat}
{code}
bq. orange block quote bq. orange block quote
Multiple definitions, tight: Multiple definitions, tight:
@ -292,16 +288,14 @@ foo
This should be a code block, though: This should be a code block, though:
{code:java} {noformat}
<div> <div>
foo foo
</div> </div>{noformat}
{code}
As should this: As should this:
{code:java} {noformat}
<div>foo</div> <div>foo</div>{noformat}
{code}
Now, nested: Now, nested:
foo foo
@ -312,16 +306,14 @@ Multiline:
Code block: Code block:
{code:java} {noformat}
<!-- Comment --> <!-- Comment -->{noformat}
{code}
Just plain comment, with trailing spaces on the line: Just plain comment, with trailing spaces on the line:
Code: Code:
{code:java} {noformat}
<hr /> <hr />{noformat}
{code}
Hrs: Hrs:
---- ----
@ -478,9 +470,8 @@ Indented [thrice|/url].
This should \[not\]\[\] be a link. This should \[not\]\[\] be a link.
{code:java} {noformat}
[not]: /url [not]: /url{noformat}
{code}
Foo [bar|/url/]. Foo [bar|/url/].
Foo [biz|/url/]. Foo [biz|/url/].
@ -506,9 +497,8 @@ An e-mail address: [mailto:nobody@nowhere.net]
bq. Blockquoted: [http://example.com/] bq. Blockquoted: [http://example.com/]
Auto-links should not occur here: {{<http://example.com/>}} Auto-links should not occur here: {{<http://example.com/>}}
{code:java} {noformat}
or here: <http://example.com/> or here: <http://example.com/>{noformat}
{code}
---- ----
h1. {anchor:images}Images h1. {anchor:images}Images
From "Voyage dans la Lune" by Georges Melies \(1902): From "Voyage dans la Lune" by Georges Melies \(1902):
@ -534,9 +524,8 @@ This paragraph should not be part of the note, as it is not indented.
Subsequent blocks are indented to show that they belong to the footnote \(as with list items). Subsequent blocks are indented to show that they belong to the footnote \(as with list items).
{code:java} {noformat}
{ <code> } { <code> }{noformat}
{code}
If you want, you can indent every line, but you can also be lazy and just indent the first line of each block. If you want, you can indent every line, but you can also be lazy and just indent the first line of each block.