|
@@ -99,6 +99,9 @@ const htmlToLaTeX = (documentElement: HTMLElement) => {
|
|
|
// pre-process table elements
|
|
// pre-process table elements
|
|
|
processTables(documentElement)
|
|
processTables(documentElement)
|
|
|
|
|
|
|
|
|
|
+ // pre-process lists
|
|
|
|
|
+ processLists(documentElement)
|
|
|
|
|
+
|
|
|
// protect special characters in non-LaTeX text nodes
|
|
// protect special characters in non-LaTeX text nodes
|
|
|
protectSpecialCharacters(documentElement)
|
|
protectSpecialCharacters(documentElement)
|
|
|
|
|
|
|
@@ -214,6 +217,18 @@ const matchingParents = (element: HTMLElement, selector: string) => {
|
|
|
return matches
|
|
return matches
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+const processLists = (element: HTMLElement) => {
|
|
|
|
|
+ for (const list of element.querySelectorAll('ol,ul')) {
|
|
|
|
|
+ // if the list has only one item, replace the list with an element containing the contents of the item
|
|
|
|
|
+ if (list.childElementCount === 1) {
|
|
|
|
|
+ const div = document.createElement('div')
|
|
|
|
|
+ div.append(...list.firstElementChild!.childNodes)
|
|
|
|
|
+ list.before('\n', div, '\n')
|
|
|
|
|
+ list.remove()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
const processTables = (element: HTMLElement) => {
|
|
const processTables = (element: HTMLElement) => {
|
|
|
for (const table of element.querySelectorAll('table')) {
|
|
for (const table of element.querySelectorAll('table')) {
|
|
|
// create a wrapper element for the table and the caption
|
|
// create a wrapper element for the table and the caption
|
|
@@ -626,11 +641,13 @@ const selectors = [
|
|
|
end: () => `}\n\n`,
|
|
end: () => `}\n\n`,
|
|
|
}),
|
|
}),
|
|
|
createSelector({
|
|
createSelector({
|
|
|
|
|
+ // selector: 'ul:has(> li:nth-child(2))', // only select lists with at least 2 items (once Firefox supports :has())
|
|
|
selector: 'ul',
|
|
selector: 'ul',
|
|
|
start: element => `\n\n${listIndent(element)}\\begin{itemize}`,
|
|
start: element => `\n\n${listIndent(element)}\\begin{itemize}`,
|
|
|
end: element => `\n${listIndent(element)}\\end{itemize}\n`,
|
|
end: element => `\n${listIndent(element)}\\end{itemize}\n`,
|
|
|
}),
|
|
}),
|
|
|
createSelector({
|
|
createSelector({
|
|
|
|
|
+ // selector: 'ol:has(> li:nth-child(2))', // only select lists with at least 2 items (once Firefox supports :has())
|
|
|
selector: 'ol',
|
|
selector: 'ol',
|
|
|
start: element => `\n\n${listIndent(element)}\\begin{enumerate}`,
|
|
start: element => `\n\n${listIndent(element)}\\begin{enumerate}`,
|
|
|
end: element => `\n${listIndent(element)}\\end{enumerate}\n`,
|
|
end: element => `\n${listIndent(element)}\\end{enumerate}\n`,
|