/* * Copyright (c) 2018 Bevilacqua Joey. */ package ch.usi.inf.atelier.group1.jekyll import org.jsoup.Jsoup import org.jsoup.parser.Parser import java.text.SimpleDateFormat import java.util.* import java.util.regex.Pattern class HtmlToLatexWriter(private var content: String, private val singlePage: Boolean) { private val document = StringBuilder() /** * Prepare the Latex file * and insert the header */ fun start() { document.clear() insert(HEADER, afterLine = true) } /** * Begin the document and insert the title * and table of contents automatically */ fun beginDocument() { insert("\\begin{document}", afterLine = true) insert("\\maketitle", afterLine = true) insert("\\tableofcontents", afterLine = true) insert("\\newpage", afterLine = true) } /** * Store the converted html text into * the writer content so it can be later exported */ fun commit() { insert(content) } /** * End the document */ fun endDocument() { insert("\\end{document}", afterLine = true) } /** * Insert a bold text in the document */ fun changeBold() { content = content.replaceTag("", "", "\\textbf{", "}") } /** * Replace
with a LaTeX newline */ fun changeBr() { content = content.replaceTag("

", null, "\\\\", null) .replaceTag("
", null, "\\\\", null) .replaceTag("

", null, "\\\\", null) .replaceTag("
", null, "\\\\", null) } /** * Replace with LaTeX \texttt */ fun changeCode() { content = content.replaceTag("", "", "\\texttt{", "}") } /** * Replace with LaTeX \emph */ fun changeItalics() { content = content.replaceTag("", "", "\\emph{", "}") } /** * Replace with LaTeX footNote url */ fun changeLink() { content = content.replace("{{ site.baseurl }}/", "www.theshell.ch/") // "" val pattern = Pattern.compile("(.*?)") val matcher = pattern.matcher(content) while (matcher.find()) { val text = matcher.group(3) val url = matcher.group(1) content = content.replace(matcher.group(0), LINK.format(url, text)) } } /** * Replace