diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2018-03-23 07:46:44 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-23 07:46:44 +0000 |
commit | 93f25bc4bf55415e7f1474ff394e097843f58e65 (patch) | |
tree | 9635420d9b89bfad530e781f463e36b3d234ca6c | |
parent | aec5955e14eda3a5f2b41ad8e1ba1bc6f15a4ca3 (diff) | |
parent | 2568ddc17a614c7ef3d06d7bb189c53eadd63e31 (diff) | |
download | FMark-93f25bc4bf55415e7f1474ff394e097843f58e65.tar.gz FMark-93f25bc4bf55415e7f1474ff394e097843f58e65.zip |
Merge pull request #164 from ymherklotz/passthrough
Passthrough
-rw-r--r-- | FMark/src/Common/Lexer/Lexer.fs | 5 | ||||
-rw-r--r-- | FMark/src/Common/Lexer/LexerTest.fs | 8 | ||||
-rw-r--r-- | FMark/src/Common/MarkdownGen/MarkdownGen.fs | 21 | ||||
-rw-r--r-- | FMark/src/Common/Types.fs | 3 | ||||
-rw-r--r-- | FMark/src/FMarkCLI/FMarkCLI.fs | 19 | ||||
-rw-r--r-- | examples/example.fmark | 5 | ||||
-rw-r--r-- | examples/macros.fmark | 23 |
7 files changed, 55 insertions, 29 deletions
diff --git a/FMark/src/Common/Lexer/Lexer.fs b/FMark/src/Common/Lexer/Lexer.fs index 6fdb160..a7bd111 100644 --- a/FMark/src/Common/Lexer/Lexer.fs +++ b/FMark/src/Common/Lexer/Lexer.fs @@ -80,8 +80,9 @@ let nextToken state s = /// Lexes a whole string and returns the result as a Token list let lexS state source = let rec lexS' state s tokList = - match s with - | ""-> ENDLINE :: tokList + match s, state with + | "", InHTMLTag _ -> tokList + | "", _ -> ENDLINE :: tokList | _ -> let (nt, st'), nstate = nextToken state s nt :: tokList |> lexS' nstate st' diff --git a/FMark/src/Common/Lexer/LexerTest.fs b/FMark/src/Common/Lexer/LexerTest.fs index 84fcf63..7de338d 100644 --- a/FMark/src/Common/Lexer/LexerTest.fs +++ b/FMark/src/Common/Lexer/LexerTest.fs @@ -329,7 +329,7 @@ let lexTest = "HTML image tag", "Embedding an <img src=\"https://github.com/IMAGE\"> in text", - [LITERAL "Embedding"; WHITESPACE 1; LITERAL "an"; WHITESPACE 1; LITERAL"<img src=\"https://github.com/IMAGE\">" + [LITERAL "Embedding"; WHITESPACE 1; LITERAL "an"; WHITESPACE 1; LITERAL "<img src=\"https://github.com/IMAGE\">" WHITESPACE 1; LITERAL "in"; WHITESPACE 1; LITERAL "text"; ENDLINE] "A lot of nested tags", @@ -340,15 +340,15 @@ let lexTest = "Half opened tag should just be outputted", "<a><", - [LITERAL "<a>"; LITERAL "<"; ENDLINE] + [LITERAL "<a>"; LITERAL "<"] "Half opened with text after should be as expected", "<a><This text should appear as normal", - [LITERAL "<a>"; LITERAL "<This text should appear as normal"; ENDLINE] + [LITERAL "<a>"; LITERAL "<This text should appear as normal"] "Wrong html close tag should be passed through", "<p></>s", - [LITERAL "<p>"; LITERAL "</>s"; ENDLINE] + [LITERAL "<p>"; LITERAL "</>s"] ] /// Tests for the complete lexers with a string list as input diff --git a/FMark/src/Common/MarkdownGen/MarkdownGen.fs b/FMark/src/Common/MarkdownGen/MarkdownGen.fs index 8abf61c..13008ef 100644 --- a/FMark/src/Common/MarkdownGen/MarkdownGen.fs +++ b/FMark/src/Common/MarkdownGen/MarkdownGen.fs @@ -74,9 +74,9 @@ let mdTable (rows: PRow list) = | false -> mdInlineElements line |> (fun cellContent -> pStr + cellContent + "|") - + List.fold (cellsFolder alignRow) "|" row - + let foldRows alignRow rows = let rowsFolder alignRow pStr row = pStr + (foldCells alignRow) row + "\n" @@ -90,20 +90,20 @@ let mdTable (rows: PRow list) = /// recursively process a list let rec mdList list = let mdListItem ord tab (pStr,pCount) li = - let makeTabs num = + let makeTabs num = if num <= 0 then "" else String.replicate num "\t" - let retFold s = pStr + s, pCount + 1; + let retFold s = pStr + s, pCount + 1 match li with - | StringItem(line) -> mdInlineElements line |> (fun s -> + | StringItem(line) -> mdInlineElements line |> (fun s -> match ord,s with | _,"" -> "" - | true,_ -> + | true,_ -> sprintf "%s%i. %s\n" (makeTabs tab) pCount s |> logPassN logger.Debug - | false,_ -> + | false,_ -> sprintf "%s- %s\n" (makeTabs tab) s) |> retFold | NestedList(list) -> mdList list |> retFold - + match list with | {ListType=lt; ListItem=liS; Depth=d} -> let ord = match lt with | OL _ -> true | UL -> false @@ -115,7 +115,7 @@ let mdHeader header = match header with | {HeaderName=line;Level=lv} -> (line |> mdInlineElements) - |> sprintf "%s %s\n" (String.replicate lv "#") + |> sprintf "%s %s\n" (String.replicate lv "#") /// process HTML body part let mdBody pObjs = @@ -131,6 +131,3 @@ let mdBody pObjs = //| Footnote (fnId, _) -> mdInlineFootnote fnId | _ -> sprintf "%A is not implemented" pObj List.fold folder "" pObjs - - - diff --git a/FMark/src/Common/Types.fs b/FMark/src/Common/Types.fs index a87aa19..65ed79b 100644 --- a/FMark/src/Common/Types.fs +++ b/FMark/src/Common/Types.fs @@ -25,6 +25,7 @@ type TFrmtedString = | Strike of InlineElement list | Literal of string | Code of string + and InlineElement = | FrmtedString of TFrmtedString | Link of HyperText: TFrmtedString * URL: string @@ -84,4 +85,4 @@ type Cell with member c.GetParams = match c with | Contents(toks,head,align) -> toks,head,align -type OutFormat = HTML | Markdown
\ No newline at end of file +type OutFormat = HTML | Markdown diff --git a/FMark/src/FMarkCLI/FMarkCLI.fs b/FMark/src/FMarkCLI/FMarkCLI.fs index 667a720..0364bb9 100644 --- a/FMark/src/FMarkCLI/FMarkCLI.fs +++ b/FMark/src/FMarkCLI/FMarkCLI.fs @@ -48,6 +48,7 @@ let setLoggerLevel (r:ParseResults<CLIArguments>)= r.GetResult(Loglevel,defaultValue=LogLevel.FATAL) |> function | l -> globLog <- Logger(l) // update the global logger with the new log value r + let welcomeMsg a = globLog.Info None "Welcome to FMark!" a @@ -69,15 +70,15 @@ let processCLI argv = |> ifFlagRunTests |> ifFileReadFrom |> function - | None(_) -> () // Do nothing - | Some(instr,fname) -> - let format = results.GetResult(Format,defaultValue = HTML) // Find out format and output file name, convert. - let defaultOutfile = if format=HTML then replaceChars "\.[a-zA-Z]+$" ".html" fname else replaceChars "\.[a-zA-Z]+$" "1.md" fname - let outFile = results.GetResult(Output,defaultValue=defaultOutfile) - FMark.processString "" format instr - |> function - | Ok(s) - | Error(s) -> FileIO.writeToFile outFile s + | None(_) -> () // Do nothing + | Some(instr,fname) -> + let format = results.GetResult(Format,defaultValue = HTML) // Find out format and output file name, convert. + let defaultOutfile = if format=HTML then replaceChars "\.[a-zA-Z]+$" ".html" fname else replaceChars "\.[a-zA-Z]+$" "1.md" fname + let outFile = results.GetResult(Output,defaultValue=defaultOutfile) + FMark.processString "" format instr + |> function + | Ok(s) + | Error(s) -> FileIO.writeToFile outFile s [<EntryPoint>] let main argv = diff --git a/examples/example.fmark b/examples/example.fmark index 61dfc7d..a22859e 100644 --- a/examples/example.fmark +++ b/examples/example.fmark @@ -1,12 +1,15 @@ - # FMark Example +{{ include ./macros.fmark }} + ## Table of contents %%TOC ## Macros +{{ input(This is the text to be inputted into the Textbox) }} + {% macro make_table(00;01;02;10;11;12;20;21;22) |{{00}}|{{01}}|{{02}}| diff --git a/examples/macros.fmark b/examples/macros.fmark new file mode 100644 index 0000000..6868b15 --- /dev/null +++ b/examples/macros.fmark @@ -0,0 +1,23 @@ +<script type="text/javascript"> + + function loadCSS(filename){ + var file = document.createElement("link"); + file.setAttribute("rel", "stylesheet"); + file.setAttribute("type", "text/css"); + file.setAttribute("href", filename); + document.head.appendChild(file); + + } + +</script> + +{% macro input(text) + +<form action="/html/tags/html_form_tag_action.cfm" method="post"> +<textarea name="comments" id="comments" style="width:92%;height:140px;padding:2%;font-size:1.2em;border:12px outset #6DB72C;"> +{{text}} +</textarea><br> +<input type="submit" value="Submit"> +</form> + +%}
\ No newline at end of file |