Skip to content
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

various fixes #68

Merged
merged 3 commits into from
Aug 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions worker/src/util/adoc2html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,14 @@ class FranklinConverter implements AdocTypes.Converter {
section: (node) => {
const level = node.getLevel();
const title = node.getTitle();
const id = node.getId();
const tag = `h${level + 1}`;
const blocks = node.getBlocks() as AdocTypes.AbstractBlock[];
const closer = this.sectionDepth > 0 ? '</div>' : '';
this.sectionDepth += 1;

const content = `
${title ? `<${tag}>${title}</${tag}>` : ''}
${title ? `<${tag}${!id.startsWith('_') ? ` id="${id}"` : ''}>${title}</${tag}>` : ''}
${blocks.map((block) => this.convert(block)).join('\n')}`;

const wrapper = `${closer}<div>${content}${closer ? '' : '</div>'}`;
Expand Down Expand Up @@ -268,7 +269,14 @@ class FranklinConverter implements AdocTypes.Converter {
}

const href = book.resolve(`/_graphics/${src}`);
return /* html */`<img src="${href}" alt="${node.getAttribute('alt') as string || ''}" width="${node.getAttribute('width') as string}">`;
const sizes = [];
if (node.getAttribute('width')) {
sizes.push(`width="${node.getAttribute('width') as string}"`);
}
if (node.getAttribute('height')) {
sizes.push(`height="${node.getAttribute('height') as string}"`);
}
return /* html */`<img src="${href}" alt="${node.getAttribute('alt') as string || ''}"${sizes.length ? `${sizes.join(' ')}` : ''}>`;
},
table: (node) => {
const title = node.getTitle();
Expand All @@ -291,9 +299,9 @@ class FranklinConverter implements AdocTypes.Converter {
makeBlock(name: string, content: string, variants: string[] = [], singleCell = false): string {
const variantStr = variants.map(toClassName).join(' ');
return /* html */`
<div class="${toClassName(name)}${variantStr ? ` ${variantStr}` : ''}">
${singleCell ? '<div><div>\n' : ''}${content.trim()}${singleCell ? '\n</div></div>' : ''}
</div>`;
< div class="${toClassName(name)}${variantStr ? ` ${variantStr}` : ''}" >
${singleCell ? '<div><div>\n' : ''}${content.trim()}${singleCell ? '\n</div></div>' : ''}
</div>`;
}

tableToTableBlock(node: AdocTypes.Table): string {
Expand Down