diff options
author | Karl Berry <karl@freefriends.org> | 2024-07-14 20:19:05 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2024-07-14 20:19:05 +0000 |
commit | 31e47b2b4385332095798ee4d2c322bdcefbff54 (patch) | |
tree | 02614202ec16fce94c1ed38169cdcf5127b6ba4a /Master/texmf-dist/doc/luatex | |
parent | b19bbb0c178273e831d98bf135c76ca60a0c2580 (diff) |
luaxml (14jul24)
git-svn-id: svn://tug.org/texlive/trunk@71803 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/luatex')
-rw-r--r-- | Master/texmf-dist/doc/luatex/luaxml/README | 2 | ||||
-rw-r--r-- | Master/texmf-dist/doc/luatex/luaxml/luaxml.pdf | bin | 119150 -> 124725 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/luatex/luaxml/luaxml.tex | 92 |
3 files changed, 92 insertions, 2 deletions
diff --git a/Master/texmf-dist/doc/luatex/luaxml/README b/Master/texmf-dist/doc/luatex/luaxml/README index 5df074c453b..6a81ab25ce0 100644 --- a/Master/texmf-dist/doc/luatex/luaxml/README +++ b/Master/texmf-dist/doc/luatex/luaxml/README @@ -32,7 +32,7 @@ Author ------ Michal Hoftich Email: michal.h21@gmail.com -Version: v0.1r, 2024-02-23 +Version: v0.2, 2024-07-14 Original authors: Paul Chakravarti and Manoel Campos (http://manoelcampos.com) diff --git a/Master/texmf-dist/doc/luatex/luaxml/luaxml.pdf b/Master/texmf-dist/doc/luatex/luaxml/luaxml.pdf Binary files differindex f574a0a5287..071fa4e4cd0 100644 --- a/Master/texmf-dist/doc/luatex/luaxml/luaxml.pdf +++ b/Master/texmf-dist/doc/luatex/luaxml/luaxml.pdf diff --git a/Master/texmf-dist/doc/luatex/luaxml/luaxml.tex b/Master/texmf-dist/doc/luatex/luaxml/luaxml.tex index 5031a0468e2..bf3b8fbaa74 100644 --- a/Master/texmf-dist/doc/luatex/luaxml/luaxml.tex +++ b/Master/texmf-dist/doc/luatex/luaxml/luaxml.tex @@ -7,7 +7,7 @@ \usepackage{framed} % Version is defined in the makefile, use default values when compiled directly \ifdefined\version\else -\def\version{v0.1r} +\def\version{v0.2} \let\gitdate\date \fi \newcommand\modulename[1]{\subsection{#1}\label{sec:#1}} @@ -99,6 +99,67 @@ end \end{luacode*} \end{framed} +\subsection{HTML parsing} + +You can parse HTML documents using the \verb|DOM_Object.html_parse| function. This parser is slower +than the default XML parser, but it can load files that would cause errors in the XML mode. +It can handle wrongly nested HTML tags, inline JavaScript and CSS styles, and other HTML features +that would cause XML errors. + +\begin{verbatim} +dom = require "luaxml-domobject" +local document = [[ +<html> +<head><title>sample</title></head> +<body> +<h1>test</h1> +<p>hello +<p>another paragraph +<ul> +<li>first +<li>second +</ul> +</body> +</html> + ]] + +-- dom.html_parse returns the DOM_Object +obj = dom.html_parse(document) +-- print names of all elements contained in body +for _, x in ipairs(obj:query_selector("body *")) do + tex.print(x:get_element_name().. "\\par") +end +\end{verbatim} + + +\begin{framed} +\begin{luacode*} +dom = require "luaxml-domobject" +local document = [[ +<html> +<head><title>sample</title></head> +<body> +<h1>test</h1> +<p>hello +<p>another paragraph +<ul> +<li>first +<li>second +</ul> +</body> +</html> + ]] + +-- dom.html_parse returns the DOM_Object +obj = dom.html_parse(document) +-- print names of all elements contained in body +for _, x in ipairs(obj:query_selector("body *")) do + tex.print(x:get_element_name().. "\\par") +end +\end{luacode*} +\end{framed} + + \subsection{Void elements} The \verb|DOM_Object.parse| function tries to support the HTML void elements, @@ -641,6 +702,35 @@ transform.print_tex("\\verb|" .. result .. "|") \end{luacode*} \end{framed} +\section{Character sets handling} + +The \texttt{luaxml-encodings} library provides functions to convert texts in legacy 8-bit encodings such as WINDOWS-1250 +or ISO-8859-2 to UTF-8. This can be useful in fixing document encoding before HTML parsing using the \texttt{luaxml-mod-html} +library. + +\subsection{Example} + + +\begin{verbatim} +kpse.set_program_name "luatex" +local encodings = require "luaxml-encodings" + +--read HTML page from the standard input +local text = io.read("*all") +-- find the character encoding in HTML metadata +local enc = encodings.find_html_encoding(text) +if enc then + -- local conversion table for the found encoding + local mapping = encodings.load_mapping(enc) + if mapping then + -- if the mapping exists, recode the HTML input and print it + local converted = encodings.recode(text, mapping) + print(converted) + end +end +\end{verbatim} + + \section{The API documentation} |