diff --git a/src/nl/hannahsten/texifyidea/editor/pasteproviders/ImagePasteProvider.kt b/src/nl/hannahsten/texifyidea/editor/pasteproviders/ImagePasteProvider.kt index cfde0b5b8..8908fb0c9 100644 --- a/src/nl/hannahsten/texifyidea/editor/pasteproviders/ImagePasteProvider.kt +++ b/src/nl/hannahsten/texifyidea/editor/pasteproviders/ImagePasteProvider.kt @@ -75,6 +75,8 @@ open class ImagePasteProvider : PasteProvider { } override fun isPastePossible(dataContext: DataContext): Boolean { + // If both paste providers could handle the content, prefer the one that handles the text instead of pasting the text as an image + if (HtmlPasteProvider().isPastePossible(dataContext)) return false val file = dataContext.getData(PlatformDataKeys.PSI_FILE) ?: return false if (file.isLatexFile().not()) return false diff --git a/src/nl/hannahsten/texifyidea/editor/pasteproviders/StyledTextHtmlToLatexConverter.kt b/src/nl/hannahsten/texifyidea/editor/pasteproviders/StyledTextHtmlToLatexConverter.kt index 011cc0f39..bfcac42f1 100644 --- a/src/nl/hannahsten/texifyidea/editor/pasteproviders/StyledTextHtmlToLatexConverter.kt +++ b/src/nl/hannahsten/texifyidea/editor/pasteproviders/StyledTextHtmlToLatexConverter.kt @@ -2,7 +2,6 @@ package nl.hannahsten.texifyidea.editor.pasteproviders import nl.hannahsten.texifyidea.file.LatexFile import org.jsoup.nodes.Element -import org.jsoup.nodes.Node class StyledTextHtmlToLatexConverter : HtmlToLatexConverter { @@ -13,6 +12,7 @@ class StyledTextHtmlToLatexConverter : HtmlToLatexConverter { */ val openingTags = hashMapOf( "b" to "\\textbf{", + "body" to "", "br" to "\n", "em" to "\\textit{", "h1" to "\\chapter*{", @@ -33,6 +33,7 @@ class StyledTextHtmlToLatexConverter : HtmlToLatexConverter { val closingTags = hashMapOf( "a" to "}", "b" to "}", + "body" to "", "br" to "", "div" to "\n", "em" to "}", @@ -54,10 +55,6 @@ class StyledTextHtmlToLatexConverter : HtmlToLatexConverter { override fun convertHtmlToLatex(htmlIn: Element, file: LatexFile): String { var latexString = "" - val environ = getCentering(htmlIn) - if (environ != "") { - latexString += "\\begin{$environ}" - } val prefix = getPrefix(htmlIn) @@ -75,22 +72,9 @@ class StyledTextHtmlToLatexConverter : HtmlToLatexConverter { else { prefix + content + postfix } - - if (environ != "") { - latexString += "\\end{$environ}" - } return latexString } - private fun getCentering(node: Node) = when { - node.attr("align") == "center" -> "center" - node.attr("align") == "left" -> "flushleft" - node.attr("align") == "right" -> "flushright" - // latex doesnt have native support here - // node.attr("align") == "justify" -> - else -> "" - } - private fun getPrefix(element: Element): String { return specialOpeningTags[element.tagName()]?.invoke(element) ?: openingTags[element.tagName()] ?: "" } diff --git a/test/nl/hannahsten/texifyidea/editor/HtmlPasteProviderTest.kt b/test/nl/hannahsten/texifyidea/editor/HtmlPasteProviderTest.kt index 3a9f6b13a..9f0818537 100644 --- a/test/nl/hannahsten/texifyidea/editor/HtmlPasteProviderTest.kt +++ b/test/nl/hannahsten/texifyidea/editor/HtmlPasteProviderTest.kt @@ -8,6 +8,47 @@ import org.jsoup.Jsoup class HtmlPasteProviderTest : BasePlatformTestCase() { + // Uses UI elements so cannot be run +// fun testTable() { +// myFixture.configureByText("main.tex", "") +// val html = """ +// +// +// +// +// +// +// +// +// +// +// +// +// +// +// +//
Column 1Column 2
ABBR1
DPTP1,18
+// +// """.trimIndent() +// val node = Jsoup.parse(html).select("body")[0] +// val latex = HtmlPasteProvider().convertHtmlToLatex(node, myFixture.file as LatexFile) +// TestCase.assertEquals(""" +// \begin{table} +// \centering +// \begin{tabular}{ll} +// \toprule +// \textbf{Column 1} & \textbf{Column 2 cost} \\ +// \midrule +// ABBR & 1.27 \\ +// DPTP & 1,18 \\ +// \bottomrule +// \end{tabular} +// \caption{} +// \label{tab:} +// \end{table} +// """.trimIndent(), latex) +// } + fun testItalic() { myFixture.configureByText("main.tex", "") val html = "italic"