public void GenerateToc_BalidMarkdownIn_ReturnsToc() { // Assemble var generator = new TocGenerator(); var md = @" # One Body of the first ## Two Body of the second # Another One Another body ## Two: Another Two "; var expectedToc = @" * [One](#one) * [Two](#two) * [Another One](#another-one) * [Two: Another Two](#two--another-two) ".Trim(); // Act var actual = generator.GenerateToc(md); // Assert Assert.Equal(expectedToc, actual); }
public void GenerateSlug(string input, string expected) { // Assemble var generator = new TocGenerator(); // Act var actual = generator.GenerateSlug(input); // Assert Assert.Equal(expected, actual); }
static void Main(string[] args) { // set up logging clog = LoggingConfigurator.configureLogging(); clog.Info("Hello from Common Logging"); // create a dir to save the output docx string projectDir = System.IO.Directory.GetParent( System.IO.Directory.GetParent( Environment.CurrentDirectory.ToString()).ToString()).ToString() + "\\"; System.IO.Directory.CreateDirectory(projectDir + "OUT"); // docx4j.properties .. add as URL the dir containing docx4j.properties Plutext.PropertiesConfigurator.setDocx4jPropertiesDir(projectDir + @"src\samples\resources\"); // create WordprocessingMLPackage, representing the docx // and add some content to it WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(); MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart(); populateWithContent(documentPart); // Now add a ToC TocGenerator tocGenerator = new TocGenerator(wordMLPackage); // you should install your own local instance, and point to that in docx4j.properties tocGenerator.generateToc(0, " TOC \\o \"1-3\" \\h \\z \\u ", false); // Save the docx string fileOUT = projectDir + @"OUT\TocSample_Generated.docx"; Docx4J.save(wordMLPackage, new java.io.File(fileOUT), Docx4J.FLAG_SAVE_ZIP_FILE); if (update) { documentPart.addStyledParagraphOfText("Heading2", "Hello 12"); fillPageWithContent(documentPart, "Hello 12"); documentPart.addStyledParagraphOfText("Heading1", "Hello 21"); fillPageWithContent(documentPart, "Hello 21"); documentPart.addStyledParagraphOfText("Heading2", "Hello 22"); fillPageWithContent(documentPart, "Hello 22"); documentPart.addStyledParagraphOfText("Heading3", "Hello 23"); fillPageWithContent(documentPart, "Hello 23"); tocGenerator.updateToc(false); fileOUT = projectDir + @"OUT\TocSample_Updated.docx"; Docx4J.save(wordMLPackage, new java.io.File(fileOUT), Docx4J.FLAG_SAVE_ZIP_FILE); } }
public void GenerateToc_BlankInput_BlankOutput() { // Assemble var generator = new TocGenerator(); var md = ""; // Act var actual = generator.GenerateToc(md); // Assert Assert.Equal("", actual); }