git.iko.soy/typeable/pandoc
on master help sign in
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: tarleb/jira-wiki-markup#4

commiteb184d9148e8a3e8c896a71550b1f0bee8da9a21 authorAlbert Krewinkel <albert@zeitkraut.de> dateMon 8 Mar 2021, 12:40 (6 years ago) parentefc9f4a
3 files changed+37−38
src/Text/Pandoc/Writers/Jira.hs+5−5 test/Tests/Writers/Jira.hs+10 test/writer.jira+22−33
src/Text/Pandoc/Writers/Jira.hs+5−5
@@ -126,13 +126,13 @@ toJiraCode :: PandocMonad m
126126 -> Text
127127 -> JiraConverter m [Jira.Block]
128128toJiraCode (ident, classes, _attribs) code = do
129− let lang = case find (\c -> T.toLower c `elem` knownLanguages) classes of
130− Nothing -> Jira.Language "java"
131− Just l -> Jira.Language l
132129 let addAnchor b = if T.null ident
133130 then b
134131 else [Jira.Para (singleton (Jira.Anchor ident))] <> b
135− return . addAnchor . singleton $ Jira.Code lang mempty code
132+ return . addAnchor . singleton $
133+ case find (\c -> T.toLower c `elem` knownLanguages) classes of
134+ Nothing -> Jira.NoFormat mempty code
135+ Just l -> Jira.Code (Jira.Language l) mempty code
136136
137137-- | Creates a Jira definition list
138138toJiraDefinitionList :: PandocMonad m
@@ -310,7 +310,7 @@ registerNotes contents = do
310310knownLanguages :: [Text]
311311knownLanguages =
312312 [ "actionscript", "ada", "applescript", "bash", "c", "c#", "c++"
313− , "css", "erlang", "go", "groovy", "haskell", "html", "javascript"
313+ , "css", "erlang", "go", "groovy", "haskell", "html", "java", "javascript"
314314 , "json", "lua", "nyan", "objc", "perl", "php", "python", "r", "ruby"
315315 , "scala", "sql", "swift", "visualbasic", "xml", "yaml"
316316 ]
test/Tests/Writers/Jira.hs+10
@@ -68,5 +68,15 @@ tests =
6868 spanWith ("unicorn", [], []) (str "Unicorn") =?>
6969 "{anchor:unicorn}Unicorn"
7070 ]
71+
72+ , testGroup "code"
73+ [ "code block with known language" =:
74+ codeBlockWith ("", ["java"], []) "Book book = new Book(\"Algebra\")" =?>
75+ "{code:java}\nBook book = new Book(\"Algebra\")\n{code}"
76+
77+ , "code block without language" =:
78+ codeBlockWith ("", [], []) "preformatted\n text.\n" =?>
79+ "{noformat}\npreformatted\n text.\n{noformat}"
80+ ]
7181 ]
7282 ]
test/writer.jira+22−33
@@ -33,11 +33,10 @@ bq. This is a block quote. It is pretty short.
3333{quote}
3434Code in a block quote:
3535
36−{code:java}
36+{noformat}
3737sub status {
3838 print "working";
39−}
40−{code}
39+}{noformat}
4140A list:
4241
4342# item one
@@ -56,22 +55,20 @@ And a following paragraph.
5655h1. {anchor:code-blocks}Code Blocks
5756Code:
5857
59−{code:java}
58+{noformat}
6059---- (should be four hyphens)
6160
6261sub status {
6362 print "working";
6463}
6564
66−this code block is indented by one tab
67−{code}
65+this code block is indented by one tab{noformat}
6866And:
6967
70−{code:java}
68+{noformat}
7169 this code block is indented by two tabs
7270
73−These should not be escaped: \$ \\ \> \[ \{
74−{code}
71+These should not be escaped: \$ \\ \> \[ \{{noformat}
7572----
7673h1. {anchor:lists}Lists
7774h2. {anchor:unordered}Unordered
@@ -236,9 +233,8 @@ red fruit
236233contains seeds, crisp, pleasant to taste
237234* *_orange_*
238235orange fruit
239−{code:java}
240−{ orange code block }
241−{code}
236+{noformat}
237+{ orange code block }{noformat}
242238bq. orange block quote
243239
244240Multiple definitions, tight:
@@ -292,16 +288,14 @@ foo
292288
293289This should be a code block, though:
294290
295−{code:java}
291+{noformat}
296292<div>
297293 foo
298−</div>
299−{code}
294+</div>{noformat}
300295As should this:
301296
302−{code:java}
303−<div>foo</div>
304−{code}
297+{noformat}
298+<div>foo</div>{noformat}
305299Now, nested:
306300
307301foo
@@ -312,16 +306,14 @@ Multiline:
312306
313307Code block:
314308
315−{code:java}
316−<!-- Comment -->
317−{code}
309+{noformat}
310+<!-- Comment -->{noformat}
318311Just plain comment, with trailing spaces on the line:
319312
320313Code:
321314
322−{code:java}
323−<hr />
324−{code}
315+{noformat}
316+<hr />{noformat}
325317Hr’s:
326318
327319----
@@ -478,9 +470,8 @@ Indented [thrice|/url].
478470
479471This should \[not\]\[\] be a link.
480472
481−{code:java}
482−[not]: /url
483−{code}
473+{noformat}
474+[not]: /url{noformat}
484475Foo [bar|/url/].
485476
486477Foo [biz|/url/].
@@ -506,9 +497,8 @@ An e-mail address: [mailto:nobody@nowhere.net]
506497bq. Blockquoted: [http://example.com/]
507498Auto-links should not occur here: {{<http://example.com/>}}
508499
509−{code:java}
510−or here: <http://example.com/>
511−{code}
500+{noformat}
501+or here: <http://example.com/>{noformat}
512502----
513503h1. {anchor:images}Images
514504From "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.
534524
535525Subsequent blocks are indented to show that they belong to the footnote \(as with list items).
536526
537−{code:java}
538− { <code> }
539−{code}
527+{noformat}
528+ { <code> }{noformat}
540529If you want, you can indent every line, but you can also be lazy and just indent the first line of each block.
541530
542531