First properly working version.
This commit is contained in:
@ -17,7 +17,10 @@ function divToTeX($node):string {
|
||||
$type = get_class($node);
|
||||
$output = "";
|
||||
|
||||
if ($type === "DOMText") return $node->textContent;
|
||||
if ($type === "DOMText") {
|
||||
if (trim($node->nodeValue) == "") return "";
|
||||
return $node->textContent;
|
||||
}
|
||||
else {
|
||||
if ($node->tagName == "img") {
|
||||
$output = "
|
||||
@ -42,18 +45,21 @@ function divToTeX($node):string {
|
||||
}
|
||||
else {
|
||||
$output .= "
|
||||
\\itemize{%
|
||||
{
|
||||
\\begin{itemize}%
|
||||
";
|
||||
foreach ($node->childNodes as $childNode) {
|
||||
$output .= divToTeX($childNode);
|
||||
}
|
||||
$output .= "
|
||||
\\end{itemize}
|
||||
}%
|
||||
%";
|
||||
}
|
||||
}
|
||||
else if ($node->tagName == "li") {
|
||||
$output .= "\\item";
|
||||
$output .= "
|
||||
\\item";
|
||||
if ($node->getAttribute("data-title") != "") $output .= "[" . transform($node->getAttribute("data-title")) . "]{ \\hfill \\\\";
|
||||
else $output .= "{%
|
||||
";
|
||||
@ -65,7 +71,8 @@ function divToTeX($node):string {
|
||||
";
|
||||
}
|
||||
else if ($node->tagName == "h4") {
|
||||
$output .= "\\subsection{%
|
||||
$output .= "
|
||||
\\subsection{%
|
||||
";
|
||||
foreach ($node->childNodes as $childNode) {
|
||||
$output .= divToTeX($childNode);
|
||||
@ -75,7 +82,8 @@ function divToTeX($node):string {
|
||||
";
|
||||
}
|
||||
else if ($node->tagName == "h5") {
|
||||
$output .= "\\subsubsection{%
|
||||
$output .= "
|
||||
\\subsubsection{%
|
||||
";
|
||||
foreach ($node->childNodes as $childNode) {
|
||||
$output .= divToTeX($childNode);
|
||||
@ -92,6 +100,16 @@ function divToTeX($node):string {
|
||||
}
|
||||
$output .= "%
|
||||
}%
|
||||
";
|
||||
}
|
||||
else if ($node->tagName == "p") {
|
||||
$output .= "
|
||||
";
|
||||
foreach ($node->childNodes as $childNode) {
|
||||
$output .= divToTeX($childNode);
|
||||
}
|
||||
$output .= "
|
||||
|
||||
";
|
||||
}
|
||||
else if ($node->tagName == "a") {
|
||||
@ -128,8 +146,8 @@ function DOMtoTeX(DOMElement $inputs, string $folder) {
|
||||
|
||||
$centerTextTeX = function($content, $centered = false) {
|
||||
if ($centered) $output = "
|
||||
\centerVertically{
|
||||
$content
|
||||
\centerVertically{%
|
||||
$content
|
||||
}
|
||||
";
|
||||
else $output = $content;
|
||||
@ -189,6 +207,10 @@ function DOMtoTeX(DOMElement $inputs, string $folder) {
|
||||
|
||||
}
|
||||
|
||||
$output = explode(PHP_EOL, $output);
|
||||
foreach ($output as $key => $value) $output[$key] = trim($value);
|
||||
$output = implode(PHP_EOL, $output);
|
||||
|
||||
if (isset($concordanceIDFile[$chapterID])) {
|
||||
if (!file_exists(__DIR__ . "/$folder")) mkdir(__DIR__ . "/$folder");
|
||||
file_put_contents(__DIR__ . "/" . $folder . "/" . $concordanceIDFile[$chapterID], $output);
|
||||
|
Reference in New Issue
Block a user