aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitattributes1
-rw-r--r--FMark/src/Common/HTMLGen/HTMLGen.fs24
-rw-r--r--FMark/src/Common/HTMLGen/HTMLGenHelpers.fs2
-rw-r--r--FMark/src/Common/HTMLGen/HTMLGenTester.fs28
4 files changed, 55 insertions, 0 deletions
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..885859e
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+FMark/js/*.js linguist-vendored=true \ No newline at end of file
diff --git a/FMark/src/Common/HTMLGen/HTMLGen.fs b/FMark/src/Common/HTMLGen/HTMLGen.fs
index bd7cf3c..8954ad7 100644
--- a/FMark/src/Common/HTMLGen/HTMLGen.fs
+++ b/FMark/src/Common/HTMLGen/HTMLGen.fs
@@ -238,3 +238,27 @@ let strBody pObjs =
| _ -> sprintf "%A is not implemented" pObj
List.fold folder "" pObjs
+
+/// generate HTML head
+let genHead htmlTitle =
+ let metaData =
+ [
+ [("name", "viewport");("content", "width=device-width")]
+ ]
+ let genMetadata pStr md =
+ pStr + attachMetaTag "meta" md
+ List.fold genMetadata "" metaData
+ + attachSimpleTag "title" htmlTitle
+
+ |> attachSimpleTag "head"
+
+/// generate HTML body
+let genBody pObjs =
+ strBody pObjs
+ |> attachSimpleTag "body"
+
+/// top level HTMLGen
+let genHTML (htmlTitle, pObjs) =
+ attachMetaTag "!DOCTYPE" ["html", ""]
+ + genHead htmlTitle
+ + genBody pObjs \ No newline at end of file
diff --git a/FMark/src/Common/HTMLGen/HTMLGenHelpers.fs b/FMark/src/Common/HTMLGen/HTMLGenHelpers.fs
index e59ca7f..a2425a4 100644
--- a/FMark/src/Common/HTMLGen/HTMLGenHelpers.fs
+++ b/FMark/src/Common/HTMLGen/HTMLGenHelpers.fs
@@ -40,3 +40,5 @@ let attachHTMLTag (tagName, attributes: list<string * string>, needCloseTag) (co
/// attach (tagName,noAttr,closeTag)
let attachSimpleTag tagName = attachHTMLTag (tagName,[],true)
+
+let attachMetaTag tagName attrs = attachHTMLTag (tagName,attrs,false) ""
diff --git a/FMark/src/Common/HTMLGen/HTMLGenTester.fs b/FMark/src/Common/HTMLGen/HTMLGenTester.fs
index 82532dc..07fa36f 100644
--- a/FMark/src/Common/HTMLGen/HTMLGenTester.fs
+++ b/FMark/src/Common/HTMLGen/HTMLGenTester.fs
@@ -146,6 +146,16 @@ let inlineFootnoteTests =
]
[<Tests>]
+let ``HTML head generation test``=
+ makeExpectoTestList id id genHead "HTML head generation test" [
+ (
+ "tiny title",
+ "<head><meta name=\"viewport\" content=\"width=device-width\"><title>tiny title</title></head>",
+ "simple header"
+ );
+ ]
+
+[<Tests>]
let TOCTests =
let hLst1 = [{HeaderName=[FrmtedString(Literal "header1")]; Level=1}
;{HeaderName=[FrmtedString(Literal "header2")]; Level=1}
@@ -255,4 +265,22 @@ let fullBodyTests =
"<p>Go go go!<a href=\"brokenURL\">broken link</a>Come!</p>"]
, "the bodyshop"
);
+ ]
+
+[<Tests>]
+let ``global simple test`` =
+ makeExpectoTestList id id genHTML "top level genHTML test" [
+ ("FMarkToHtml fisrt release",
+ [
+ Header{HeaderName=[FrmtedString(Literal "header")]; Level=1};
+ List{ListType=UL;ListItem=
+ [StringItem[FrmtedString(Literal "first")]; StringItem[FrmtedString(Literal "second")];
+ NestedList{ListType=OL;ListItem=
+ [StringItem[FrmtedString(Literal "first")]; StringItem[FrmtedString(Literal "second")] ];
+ Depth=2} ];
+ Depth=1};
+ Table[PCells([CellLine([FrmtedString(Literal "head")], true, Left);CellLine([FrmtedString(Literal "head")], true, Right)], true)];
+ Paragraph[[FrmtedString((Literal "Go go go!")); Link(Literal "broken link", "brokenURL")]; [FrmtedString(Literal "Come!")]]
+ ]),
+ "<!DOCTYPE html><head><meta name=\"viewport\" content=\"width=device-width\"><title>FMarkToHtml fisrt release</title></head><body><h1>header</h1><ul><li>first</li><li>second</li><ol><li>first</li><li>second</li></ol></ul><table><thead><tr><th align=\"left\">head</th><th align=\"right\">head</th></tr></thead><tbody></tbody></table><p>Go go go!<a href=\"brokenURL\">broken link</a>Come!</p></body>", "all in one"
] \ No newline at end of file