-
-
Notifications
You must be signed in to change notification settings - Fork 19
Force self-closing tags to be manually closed tags #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Also, I'd be happy to implement this functionality, including testing and such. I've done some testing locally and I think it should be as simple as adding:
https://github.com/syntax-tree/hast-util-to-html/blob/main/lib/tree.js#L124 |
Hmm, I actually think this can be solved with:
Are there any side effects of doing this that I should know about? |
The output The project you are looking for, to generate XML from HTML, is https://github.com/syntax-tree/hast-util-to-xast |
I didn't think it was, either, but then I started running into errors from Google Books and the official W3 Epub validator, which has consumed the rest of my evening/morning. Thanks for the highlight of |
I have used epubcheck, and I have never received errors using |
Hmm, it's possible. I'm currently using I seem to've solved the problems I've needed to with this approach, but I'll try to read more thru the epub spec in the "morning". |
Here’s how I turned hast, that I got from markdown and a ton of custom processing, into HTML for epub: // Utility to serialize hast as ePub XML.
import {u} from 'https://github.com/syntax-tree/unist-builder'
import {select} from 'https://github.com/syntax-tree/hast-util-select'
import {toXast} from 'https://github.com/syntax-tree/hast-util-to-xast'
import {toXml} from 'https://github.com/syntax-tree/xast-util-to-xml'
import {namespaces} from './util-namespaces.js'
export function toEpubXhtml(hastTree) {
const html = select('html', hastTree)
// Add the epub and ibooks namespaces.
if (html) {
html.properties['xmlns:epub'] = namespaces.epub
html.properties['epub:prefix'] = 'ibooks: ' + namespaces.ibooks
}
// Transform to XML.
const tree = toXast(hastTree)
// Add the XML declaration.
tree.children.unshift(
u('instruction', {name: 'xml'}, 'version="1.0"'),
u('text', '\n')
)
// Serialize.
return toXml(tree)
}
// Web + ebook namespaces.
import {webNamespaces} from 'https://github.com/wooorm/web-namespaces'
export const namespaces = {
...webNamespaces,
ibooks:
'http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/',
opf: 'http://www.idpf.org/2007/opf',
dc: 'http://purl.org/dc/elements/1.1/',
container: 'urn:oasis:names:tc:opendocument:xmlns:container',
ncx: 'http://www.daisy.org/z3986/2005/ncx/',
epub: 'http://www.idpf.org/2007/ops'
} |
Closing as |
Initial checklist
Problem
I'm trying to generate XHTML ePub documents from Markdown files for my book.
However, many popular epub readers do not support self-closing tags for tags such as
img
(including seemingly Google Play Books).Solution
I'd love to have a way to force a tag to be fully closed tag. This means that instead of:
Or
(using
closeSelfClosing
)We'd have:
Alternatives
Alternatively, instead of having all closing tags handles, we could have a:
Style API
The text was updated successfully, but these errors were encountered: