public FlowDocument DebugDocument(string text) { MarkDownLexicalAnalyzer ana = new MarkDownLexicalAnalyzer(text + "\n\n"); List<DocLexElement> lex = ana.GetDocLexList(); FlowDocGenerator fdg = new FlowDocGenerator(); fdg.DocumentFontFamily = DocumentFontFamily; fdg.DocumentNormalFontSize = DocumentNormalFontSize; fdg.DocumentHeadline1FontSize = DocumentHeadline1FontSize; fdg.DocumentHeadline2FontSize = DocumentHeadline2FontSize; fdg.DocumentHeadline3FontSize = DocumentHeadline3FontSize; fdg.DocumentHeadline4FontSize = DocumentHeadline4FontSize; fdg.DocumentHeadline5FontSize = DocumentHeadline5FontSize; fdg.CodingFontSize = CodingFontSize; fdg.CodingFontFamily = CodingFontFamily; fdg.TextAlignment = TextAlignment; fdg.HeadingTextAlignment = HeadingTextAlignment; FlowDocument doc = null; try { string xamlstr = fdg.DebugDoc(text, lex); doc = LoadXaml(xamlstr); } catch (Exception exc) { throw new DocFormatException(exc.Message); } return doc; }
public void TestHashes() { MarkDownLexicalAnalyzer an = new MarkDownLexicalAnalyzer("# Hallo Welt\n## Bin dann mal weg\nAls ich noch jung war\n"); List<DocLexElement> ergs = an.GetDocLexList(); string ress = GetAsString(ergs); Assert.AreEqual(ress, "hashes(1),word(Hallo),word(Welt),linebreak,hashes(2),word(Bin),word(dann),word(mal),word(weg),linebreak,word(Als),word(ich),word(noch),word(jung),word(war),parabreak"); }
public void TestEmphasize() { MarkDownLexicalAnalyzer an = new MarkDownLexicalAnalyzer("Hallo *kursive* Welt"); List<DocLexElement> ergs = an.GetDocLexList(); string ress = GetAsString(ergs); Assert.AreEqual(ress, "word(Hallo),emphasize,word(kursive),emphasize,word(Welt)"); }
public void TestCodeArea() { MarkDownLexicalAnalyzer an = new MarkDownLexicalAnalyzer("```x = y*3.0 + 12\n```\nHier gehts weiter"); List<DocLexElement> ergs = an.GetDocLexList(); string ress = GetAsString(ergs); Assert.AreEqual(ress, "codeblock(x = y*3.0 + 12\n),linebreak,word(Hier),word(gehts),word(weiter)"); }
public void TestBold() { MarkDownLexicalAnalyzer an = new MarkDownLexicalAnalyzer("Hallo **fette** Welt"); List<DocLexElement> ergs = an.GetDocLexList(); string ress = GetAsString(ergs); Assert.AreEqual(ress, "word(Hallo),bold,word(fette),bold,word(Welt)"); }
public void TestGetDocLexList() { MarkDownLexicalAnalyzer analyzer = new MarkDownLexicalAnalyzer("Hallo Welt"); List<DocLexElement> reslts = analyzer.GetDocLexList(); Assert.AreEqual(reslts[0].Text, "Hallo"); Assert.AreEqual(reslts[1].Text, "Welt"); analyzer.Text = "## Hallo Welt\nIch bin dann mal weg."; reslts = analyzer.GetDocLexList(); Assert.IsTrue(reslts[0].Type == DocLexElement.LexTypeEnum.hashes && reslts[0].Level==2); Assert.AreEqual(reslts[1].Text, "Hallo"); Assert.AreEqual(reslts[2].Text, "Welt"); analyzer.Text = "```\nHallo Welt\nIch bin dann mal weg.\n```"; reslts = analyzer.GetDocLexList(); Assert.IsTrue(reslts[0].Type == DocLexElement.LexTypeEnum.codeblock); }
/// <summary> /// Das FlowDocument aus dem Markup-Text aufbauen /// </summary> /// <param name="text">Text in Markup-Form</param> /// <returns>Test als FlowDocument formatiert</returns> public string FormatDocument(string text) { MarkDownLexicalAnalyzer ana = new MarkDownLexicalAnalyzer(text + "\n\n"); List<DocLexElement> lex = ana.GetDocLexList(); FlowDocGenerator fdg = new FlowDocGenerator(); fdg.DocumentFontFamily = DocumentFontFamily; fdg.DocumentNormalFontSize = DocumentNormalFontSize; fdg.DocumentHeadline1FontSize = DocumentHeadline1FontSize; fdg.DocumentHeadline2FontSize = DocumentHeadline2FontSize; fdg.DocumentHeadline3FontSize = DocumentHeadline3FontSize; fdg.DocumentHeadline4FontSize = DocumentHeadline4FontSize; fdg.DocumentHeadline5FontSize = DocumentHeadline5FontSize; fdg.CodingFontSize = CodingFontSize; fdg.CodingFontFamily = CodingFontFamily; fdg.TextAlignment = TextAlignment; fdg.HeadingTextAlignment = HeadingTextAlignment; return fdg.ProduceDoc(lex); }