diff options
author | Qieerb <qieerbushe7@gmail.com> | 2018-03-23 11:42:37 +0000 |
---|---|---|
committer | Qieerb <qieerbushe7@gmail.com> | 2018-03-23 11:42:37 +0000 |
commit | 124ace81526662f313c3090c758b94caaf725294 (patch) | |
tree | 6f671e2f28eb6f71a611b89bbab949c928b1a5ef /FMark | |
parent | 44175b8b32bd3f828590ec8a7a0379acabbe8a3d (diff) | |
download | FMark-124ace81526662f313c3090c758b94caaf725294.tar.gz FMark-124ace81526662f313c3090c758b94caaf725294.zip |
type change
Diffstat (limited to 'FMark')
-rw-r--r-- | FMark/src/Common/TOCite/TOCite.fs | 16 | ||||
-rw-r--r-- | FMark/src/Common/TOCite/TOCiteTest.fs | 24 | ||||
-rw-r--r-- | FMark/src/Common/Types.fs | 4 |
3 files changed, 28 insertions, 16 deletions
diff --git a/FMark/src/Common/TOCite/TOCite.fs b/FMark/src/Common/TOCite/TOCite.fs index c8f94f2..9be185a 100644 --- a/FMark/src/Common/TOCite/TOCite.fs +++ b/FMark/src/Common/TOCite/TOCite.fs @@ -1,5 +1,6 @@ module TOCite open Types +open Shared open RefParse open ParserHelperFuncs @@ -21,6 +22,15 @@ let mountedInLineParser tokLst = |> List.rev |> List.reduce List.append +/// strip header to a minimal string for id purposes +let headerIDGen id hdLine = + let rec headerIDGen' hdLine = + match hdLine with + | FrmtedString (Literal a)::tl -> a + headerIDGen' tl + | FrmtedString (Emphasis a)::tl -> (headerIDGen' a) + (headerIDGen' tl) + | _ -> "" + (headerIDGen' hdLine |> replaceChars "\ " "_") + string id + let rec tocParse tocLst depth index : THeader list * Token list = // Detect hashes with whitespace after it // printf "tocParse %A\n%A\n" depth tocLst @@ -40,10 +50,12 @@ let rec tocParse tocLst depth index : THeader list * Token list = match ind with | Some i -> let (h,t) = List.splitAt i tl + let hName = mountedInLineParser h tocParse t 0 (index+1) - |> fun (x,y) -> {HeaderName = mountedInLineParser h; Level = depth}::x, ENDLINE::ENDLINE::(HEADER index)::y + |> fun (x,y) -> {HeaderName = hName; Level = depth; RefID = (headerIDGen index hName)}::x, ENDLINE::ENDLINE::(HEADER index)::y | None -> - [{HeaderName = mountedInLineParser tl; Level = depth}], [ENDLINE;ENDLINE;HEADER index] + let hName = mountedInLineParser tl + [{HeaderName = hName; Level = depth; RefID = (headerIDGen index hName)}], [ENDLINE;ENDLINE;HEADER index] // hash without whitespace, need to rebuild hash | a::tl when depth > 0 -> tocParse tl 0 index diff --git a/FMark/src/Common/TOCite/TOCiteTest.fs b/FMark/src/Common/TOCite/TOCiteTest.fs index 22ea704..017493a 100644 --- a/FMark/src/Common/TOCite/TOCiteTest.fs +++ b/FMark/src/Common/TOCite/TOCiteTest.fs @@ -8,14 +8,14 @@ let testDataHd = [ "Basic Test", [ENDLINE;ENDLINE; HASH; WHITESPACE 1; LITERAL "H1"], ( - [{HeaderName = [FrmtedString (Literal "H1")]; Level = 1;}], + [{HeaderName = [FrmtedString (Literal "H1")]; Level = 1; RefID = "";}], [ENDLINE;ENDLINE;HEADER 0] ); "Depth Test", [ENDLINE;ENDLINE; HASH; HASH; HASH; WHITESPACE 1; LITERAL "h3"], ( - [{HeaderName = [FrmtedString (Literal "h3")]; Level = 3;}], + [{HeaderName = [FrmtedString (Literal "h3")]; Level = 3; RefID = "";}], [ENDLINE;ENDLINE;HEADER 0] ); @@ -36,7 +36,7 @@ let testDataHd = [ "Hash character support within header text", [ENDLINE;ENDLINE; HASH; WHITESPACE 1; LITERAL "H1"; HASH; WHITESPACE 1; LITERAL "H2"], ( - [{HeaderName = [FrmtedString (Literal "H1# H2")]; Level = 1;}], + [{HeaderName = [FrmtedString (Literal "H1# H2")]; Level = 1; RefID = "";}], [ENDLINE;ENDLINE;HEADER 0] ); @@ -44,7 +44,7 @@ let testDataHd = [ [LITERAL "text1"; ENDLINE;ENDLINE; HASH; WHITESPACE 1; LITERAL "H1"; ENDLINE;ENDLINE; LITERAL "text2"; ENDLINE], ( - [{HeaderName = [FrmtedString (Literal "H1")]; Level = 1;}], + [{HeaderName = [FrmtedString (Literal "H1")]; Level = 1; RefID = "";}], [LITERAL "text1"; ENDLINE;ENDLINE;HEADER 0; ENDLINE;ENDLINE; LITERAL "text2"; ENDLINE] ); @@ -52,8 +52,8 @@ let testDataHd = [ [ENDLINE;ENDLINE; HASH; HASH; WHITESPACE 1; LITERAL "h1"; ENDLINE;ENDLINE; HASH; WHITESPACE 1; LITERAL "h2"], ( - [{HeaderName = [FrmtedString (Literal "h1")]; Level = 2;}; - {HeaderName = [FrmtedString (Literal "h2")]; Level = 1;}], + [{HeaderName = [FrmtedString (Literal "h1")]; Level = 2; RefID = "";}; + {HeaderName = [FrmtedString (Literal "h2")]; Level = 1; RefID = "";}], [ENDLINE;ENDLINE;HEADER 0; ENDLINE;ENDLINE;HEADER 1] ) @@ -61,7 +61,7 @@ let testDataHd = [ [ENDLINE;ENDLINE; HASH; WHITESPACE 1; LITERAL "NotBold"; ASTERISK; LITERAL "bold"; ASTERISK], ( [{HeaderName = [FrmtedString (Literal "NotBold"); - FrmtedString (Emphasis [FrmtedString (Literal "bold")])]; Level = 1;}], + FrmtedString (Emphasis [FrmtedString (Literal "bold")])]; Level = 1; RefID = "";}], [ENDLINE;ENDLINE;HEADER 0] ); @@ -70,16 +70,16 @@ let testDataHd = [ ENDLINE;ENDLINE; LITERAL "This is a Paragraph"; ENDLINE;ENDLINE; HASH; HASH; HASH; WHITESPACE 3; ASTERISK; LITERAL "Another Title"; ASTERISK; ENDLINE], ( - [{HeaderName =[FrmtedString (Literal "h1h2")]; Level = 2;}; + [{HeaderName =[FrmtedString (Literal "h1h2")]; Level = 2; RefID = "";}; {HeaderName = [FrmtedString (Emphasis [FrmtedString (Literal "Another Title")])]; - Level = 3;}], + Level = 3; RefID = "";}], [ENDLINE;ENDLINE;HEADER 0; ENDLINE;ENDLINE; LITERAL "This is a Paragraph"; ENDLINE;ENDLINE;HEADER 1; ENDLINE] ); "Unclosed emphasis in header text", [ENDLINE;ENDLINE; HASH; WHITESPACE 1; LITERAL "NotBold"; ASTERISK; LITERAL "bold"], ( - [{HeaderName = [FrmtedString (Literal "NotBold*bold")]; Level = 1;}], + [{HeaderName = [FrmtedString (Literal "NotBold*bold")]; Level = 1; RefID = "";}], [ENDLINE;ENDLINE;HEADER 0] ); @@ -89,7 +89,7 @@ let testDataHd = [ [{HeaderName = [FrmtedString (Literal "text1"); InlineFootnote(Literal "3","footnote-3"); FrmtedString (Literal "text2"); - ]; Level = 1;}], + ]; Level = 1; RefID = "";}], [ENDLINE;ENDLINE;HEADER 0] ) @@ -216,7 +216,7 @@ let testDataFull = LITERAL "access"; WHITESPACE 1; EQUAL; WHITESPACE 1; NUMBER "2018"; MINUS; NUMBER "3"; MINUS; NUMBER "4"; ENDLINE], ( - [{HeaderName = [FrmtedString (Literal "Header1")]; Level = 1;}], + [{HeaderName = [FrmtedString (Literal "Header1")]; Level = 1; RefID = "";}], [Footnote (1,[FrmtedString (Literal "footer1")]); Citation ( "Eric", diff --git a/FMark/src/Common/Types.fs b/FMark/src/Common/Types.fs index 65ed79b..34ed027 100644 --- a/FMark/src/Common/Types.fs +++ b/FMark/src/Common/Types.fs @@ -35,7 +35,7 @@ and InlineElement = type TLine = InlineElement list -type THeader = {HeaderName: TLine; Level: int} +type THeader = {HeaderName: TLine; Level: int; RefID: string} type Ttoc = {HeaderLst: THeader list} @@ -65,7 +65,7 @@ type Ref = {Cat: RefType option; Author: Token list option; Title: Token list op type ParsedObj = | CodeBlock of string * Language - | Header of THeader * string // content of header, HTML id for linking + | Header of THeader | ContentTable of Ttoc | List of TList | Paragraph of TLine list |