Skip to content

Commit

Permalink
Merge pull request #68 from hlxsites/maxed/fixes
Browse files Browse the repository at this point in the history
various fixes
  • Loading branch information
maxakuru authored Aug 29, 2023
2 parents 62b9863 + a2d9449 commit a4381cc
Showing 1 changed file with 13 additions and 5 deletions.
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

0 comments on commit a4381cc

Please sign in to comment.