diff options
Diffstat (limited to 'FMark')
-rw-r--r-- | FMark/src/Common/HTMLGen/HTMLGen.fs | 14 | ||||
-rw-r--r-- | FMark/src/Common/HTMLGen/HTMLGenTester.fs | 6 | ||||
-rw-r--r-- | FMark/src/Common/Parser/ParserHelperFuncs.fs | 26 | ||||
-rw-r--r-- | FMark/src/Common/Parser/ParserTest.fs | 12 | ||||
-rw-r--r-- | FMark/src/Common/TOCite/TOCite.fs | 2 | ||||
-rw-r--r-- | FMark/src/Common/TOCite/TOCiteTest.fs | 2 | ||||
-rw-r--r-- | FMark/src/Common/Types.fs | 4 |
7 files changed, 33 insertions, 33 deletions
diff --git a/FMark/src/Common/HTMLGen/HTMLGen.fs b/FMark/src/Common/HTMLGen/HTMLGen.fs index 5f80e0a..c15f34a 100644 --- a/FMark/src/Common/HTMLGen/HTMLGen.fs +++ b/FMark/src/Common/HTMLGen/HTMLGen.fs @@ -4,7 +4,6 @@ open Types open Shared open Logger open HTMLGenHelpers -let dLogger = Logger(LogLevel.WARNING) /// convert TFrmtedString to string, with HTML tags where necessary let rec strFStr fStr = @@ -20,6 +19,11 @@ let rec strFStr fStr = /// not tail recursive because the code looks cleaner this way and strInlineElements eles = let convertHtml pStr ele = + let refPrint foot (ht,id) = + ht + |> strFStr + |> attachHTMLTag ("a", [("href", "#"+id)], true) + |> (fun r -> if foot then attachSimpleTag "sup" r else r) pStr + match ele with | FrmtedString fStr -> strFStr fStr @@ -27,11 +31,9 @@ and strInlineElements eles = | Picture (alt, url) -> let attrs = [("src", url); ("alt", alt)] attachHTMLTag ("img", attrs, false) "" - | Reference (ht, id) -> // style for inline referencing the footnotes and citations in the end - ht - |> strFStr - |> attachHTMLTag ("a", [("href", "#"+id)], true) - |> attachSimpleTag "sup" + // style for inline referencing the footnotes and citations in the end + | InlineCitation (ht, id) -> refPrint false (ht,id) + | InlineFootnote (ht, id) -> refPrint true (ht,id) List.fold convertHtml "" eles /// process Markdown paragraph diff --git a/FMark/src/Common/HTMLGen/HTMLGenTester.fs b/FMark/src/Common/HTMLGen/HTMLGenTester.fs index 7cc0822..e92456b 100644 --- a/FMark/src/Common/HTMLGen/HTMLGenTester.fs +++ b/FMark/src/Common/HTMLGen/HTMLGenTester.fs @@ -303,8 +303,8 @@ let reallyBigTest = ("big HTML test", [Paragraph [[FrmtedString (Literal "text1#text2")]]; Header ({HeaderName = [FrmtedString (Literal "Header1")]; Level = 1;},"Header10"); - Paragraph [[Reference (Literal "Footer1","footnote-1"); FrmtedString (Literal "text4")]]; - Paragraph [[Reference (Literal "(Wang, 2017)","footnote-Eric"); FrmtedString (Literal "text6")]]; + Paragraph [[InlineFootnote (Literal "Footer1","footnote-1"); FrmtedString (Literal "text4")]]; + Paragraph [[InlineCitation(Literal "(Wang, 2017)","footnote-Eric"); FrmtedString (Literal "text6")]]; Footnote (1,[FrmtedString (Literal "footer1")]); Citation ( "footnote-Eric",Literal "(Wang, 2017)", @@ -319,7 +319,7 @@ let reallyBigTest = "<p>text1#text2</p>"; "<h1 id=\"Header10\">Header1</h1>"; "<p><sup><a href=\"#footnote-1\">Footer1</a></sup>text4</p>"; - "<p><sup><a href=\"#footnote-Eric\">(Wang, 2017)</a></sup>text6</p>"; + "<p><a href=\"#footnote-Eric\">(Wang, 2017)</a>text6</p>"; "<p id=\"1\">[1] footer1</p>"; "<p id=\"footnote-Eric\">[footnote-Eric] Eric Wang. 2017. \"Not a real website.\" Accessed March 4, 2018. <a href=\"www.example.com/website\">www.example.com/website</a></p>"; "<script type=\"text/javascript\" async src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML\"></script>"; diff --git a/FMark/src/Common/Parser/ParserHelperFuncs.fs b/FMark/src/Common/Parser/ParserHelperFuncs.fs index 240bf9a..997af6d 100644 --- a/FMark/src/Common/Parser/ParserHelperFuncs.fs +++ b/FMark/src/Common/Parser/ParserHelperFuncs.fs @@ -430,25 +430,21 @@ let parseInLineElements2 refLst toks = |> (fun x -> x@currentLine) let makeList x = [x] let rec parseInLineElements' ftLst currentLine toks = + let styleHelper style (content, rtks, frontLiteral, backLiteral) = + let inlineContent = (parseInLines [] content |> style |> FrmtedString) + genFormat (currentLine, inlineContent, frontLiteral, backLiteral), rtks + match toks with | MatchSym BACKTICK (content, rtks) -> (content|> strAllToks|> Code|> FrmtedString )::currentLine, rtks | MatchStrongAndEm (content, rtks, frontLiteral, backLiteral) -> - let inlineContent = - parseInLines [] content |> Strong |> FrmtedString |> makeList |> Emphasis |> FrmtedString - genFormat (currentLine, inlineContent, frontLiteral, backLiteral) - , rtks + let inlineContent = (parseInLines [] content |> Strong |> FrmtedString |> makeList |> Emphasis |> FrmtedString) + genFormat (currentLine, inlineContent, frontLiteral, backLiteral), rtks | MatchStrong (content, rtks, frontLiteral, backLiteral) -> - let inlineContent = (parseInLines [] content |> Strong |> FrmtedString) - genFormat (currentLine, inlineContent, frontLiteral, backLiteral) - , rtks + styleHelper Strong (content, rtks, frontLiteral, backLiteral) | MatchEm (content, rtks, frontLiteral, backLiteral) -> - let inlineContent = (parseInLines [] content |> Emphasis |> FrmtedString) - genFormat (currentLine, inlineContent, frontLiteral, backLiteral) - , rtks + styleHelper Emphasis (content, rtks, frontLiteral, backLiteral) | MatchStrike (content, rtks, frontLiteral, backLiteral) -> - let inlineContent = (parseInLines [] content |> Strike |> FrmtedString) - genFormat (currentLine, inlineContent, frontLiteral, backLiteral) - , rtks + styleHelper Strike (content, rtks, frontLiteral, backLiteral) | MatchLink (hyperTextToks, urlToks, rtks) -> let hyperText = parseInLines [] hyperTextToks |> Line let url = strAllToks urlToks @@ -461,14 +457,14 @@ let parseInLineElements2 refLst toks = let idStr = string i match findFN i ftLst with | Ok _ -> // ok if found at least one reference in refLst - [(Literal idStr, idStr) |> Reference]@currentLine, rtks + [(Literal idStr, idStr) |> InlineFootnote]@currentLine, rtks | Error msg -> // error if no reference is found in refLst [msg |> Literal |> FrmtedString], rtks | CITATION str :: rtks -> match findCite str ftLst with | Ok ref -> // ok if found at least one reference in refLst match ref with - | Citation (id, hyperText, _) -> [(hyperText, id) |> Reference]@currentLine, rtks + | Citation (id, hyperText, _) -> [(hyperText, id) |> InlineCitation]@currentLine, rtks | _ -> failwith "non-citation in citation list" | Error msg -> // error if no reference is found in refLst [msg |> Literal |> FrmtedString], rtks diff --git a/FMark/src/Common/Parser/ParserTest.fs b/FMark/src/Common/Parser/ParserTest.fs index b912e8c..8902629 100644 --- a/FMark/src/Common/Parser/ParserTest.fs +++ b/FMark/src/Common/Parser/ParserTest.fs @@ -333,21 +333,21 @@ let ``reference tests`` = refStyleToks @[LSBRA; CARET; NUMBER "1"; RSBRA] @refToks, - [Paragraph [[Reference (Literal "1","1")]]]@refPobjs, + [Paragraph [[InlineFootnote(Literal "1","1")]]]@refPobjs, "just 1 footnote" ); ( refStyleToks @[LSBRA; CARET; LITERAL "Eric"; RSBRA] @refToks, - [Paragraph [[Reference (Literal "(Wang, 2017)","Eric")]]]@refPobjs, + [Paragraph [[InlineCitation(Literal "(Wang, 2017)","Eric")]]]@refPobjs, "just 1 citation" ); ( refStyleToks @[LITERAL "text3"; LSBRA; CARET; NUMBER "1"; RSBRA; LITERAL "text4"] @refToks, - [Paragraph [[FrmtedString (Literal "text3");Reference (Literal "1","1"); FrmtedString (Literal "text4")]]]@refPobjs, + [Paragraph [[FrmtedString (Literal "text3");InlineFootnote(Literal "1","1"); FrmtedString (Literal "text4")]]]@refPobjs, "Literal and 1 footnote" ); @@ -355,7 +355,7 @@ let ``reference tests`` = refStyleToks @[LITERAL "text5"; LSBRA; CARET; LITERAL "Eric"; RSBRA; LITERAL "text6"] @refToks, - [Paragraph [[FrmtedString (Literal "text5");Reference (Literal "(Wang, 2017)","Eric"); FrmtedString (Literal "text6")]]]@refPobjs, + [Paragraph [[FrmtedString (Literal "text5");InlineCitation(Literal "(Wang, 2017)","Eric"); FrmtedString (Literal "text6")]]]@refPobjs, "Literal and 1 citation" ); ( @@ -364,8 +364,8 @@ let ``reference tests`` = @[LITERAL "text5"; LSBRA; CARET; LITERAL "Eric"; RSBRA; LITERAL "text6"] @refToks, [Paragraph [ - [FrmtedString (Literal "text3");Reference (Literal "1","1"); FrmtedString (Literal "text4")]; - [FrmtedString (Literal "text5");Reference (Literal "(Wang, 2017)","Eric"); FrmtedString (Literal "text6")] + [FrmtedString (Literal "text3");InlineFootnote(Literal "1","1"); FrmtedString (Literal "text4")]; + [FrmtedString (Literal "text5");InlineCitation(Literal "(Wang, 2017)","Eric"); FrmtedString (Literal "text6")] ]]@refPobjs, "multiline, 1 footnote, 1 citation" ); diff --git a/FMark/src/Common/TOCite/TOCite.fs b/FMark/src/Common/TOCite/TOCite.fs index 119bd4c..88d6c8b 100644 --- a/FMark/src/Common/TOCite/TOCite.fs +++ b/FMark/src/Common/TOCite/TOCite.fs @@ -10,7 +10,7 @@ let mountedInLineParser tokLst = match tLst with | FOOTNOTE i::tl -> let s = string i - parseInLineElements toParse :: [Reference (Literal s, "footnote-"+s)] + parseInLineElements toParse :: [InlineFootnote (Literal s, "footnote-"+s)] :: mountedInLineParser' [] tl | CITATION _::tl -> mountedInLineParser' toParse tl | a::tl -> mountedInLineParser' (a::toParse) tl diff --git a/FMark/src/Common/TOCite/TOCiteTest.fs b/FMark/src/Common/TOCite/TOCiteTest.fs index 554b464..cf0a6c3 100644 --- a/FMark/src/Common/TOCite/TOCiteTest.fs +++ b/FMark/src/Common/TOCite/TOCiteTest.fs @@ -87,7 +87,7 @@ let testDataHd = [ [ENDLINE;ENDLINE; HASH; WHITESPACE 1; LITERAL "text1"; FOOTNOTE 3; LITERAL "text2"], ( [{HeaderName = [FrmtedString (Literal "text1"); - Reference (Literal "3","footnote-3"); + InlineFootnote(Literal "3","footnote-3"); FrmtedString (Literal "text2"); ]; Level = 1;}], [ENDLINE;ENDLINE;HEADER 0] diff --git a/FMark/src/Common/Types.fs b/FMark/src/Common/Types.fs index e8dbc2a..a87aa19 100644 --- a/FMark/src/Common/Types.fs +++ b/FMark/src/Common/Types.fs @@ -29,7 +29,9 @@ and InlineElement = | FrmtedString of TFrmtedString | Link of HyperText: TFrmtedString * URL: string | Picture of Alt: string * URL: string - | Reference of HyperText: TFrmtedString * ID: string + | InlineCitation of HyperText: TFrmtedString * ID: string + | InlineFootnote of HyperText: TFrmtedString * ID: string + type TLine = InlineElement list type THeader = {HeaderName: TLine; Level: int} |