mirror of
https://github.com/jzillmann/pdf-to-markdown.git
synced 2025-02-05 04:19:20 +01:00
Improve markdown rendering
This commit is contained in:
parent
55ae236928
commit
5ab8730a4b
@ -1,24 +1,38 @@
|
|||||||
import Item from 'src/Item';
|
import { groupByLine } from '../support/groupingUtils';
|
||||||
import { Converter } from 'src/convert';
|
import Item from '../Item';
|
||||||
|
import { Converter } from '../convert';
|
||||||
|
import ChangeTracker from '../debug/ChangeTracker';
|
||||||
|
import EvaluationTracker from '../debug/EvaluationTracker';
|
||||||
|
import LineItemMerger from '../debug/LineItemMerger';
|
||||||
|
|
||||||
export default class MarkdownConverter implements Converter {
|
export default class MarkdownConverter implements Converter {
|
||||||
convert(items: Item[]) {
|
convert(items: Item[]) {
|
||||||
let content = '';
|
let content = '';
|
||||||
|
|
||||||
items.forEach((item) => {
|
const itemsByLine = groupByLine(items);
|
||||||
const types = item.data['types'] || [];
|
const lineMerger = new LineItemMerger();
|
||||||
const itemText = item.data['str'];
|
itemsByLine.forEach((lineItems) => {
|
||||||
|
const lineItem = lineMerger.merge(new EvaluationTracker(), new ChangeTracker(), ['types'], lineItems);
|
||||||
|
const types = lineItem.data['types'] || [];
|
||||||
|
const itemText = lineItem.data['str'];
|
||||||
if (types.includes('H1')) {
|
if (types.includes('H1')) {
|
||||||
content += '# ' + itemText + '\n';
|
content += '# ' + itemText + '\n';
|
||||||
} else if (types.includes('H2')) {
|
} else if (types.includes('H2')) {
|
||||||
content += '## ' + itemText + '\n';
|
content += '## ' + itemText + '\n';
|
||||||
} else if (types.includes('H3')) {
|
} else if (types.includes('H3')) {
|
||||||
content += '## ' + itemText + '\n';
|
content += '### ' + itemText + '\n';
|
||||||
|
} else if (types.includes('H4')) {
|
||||||
|
content += '#### ' + itemText + '\n';
|
||||||
|
} else if (types.includes('H5')) {
|
||||||
|
content += '##### ' + itemText + '\n';
|
||||||
|
} else if (types.includes('H6')) {
|
||||||
|
content += '###### ' + itemText + '\n';
|
||||||
} else {
|
} else {
|
||||||
content += itemText;
|
content += itemText;
|
||||||
}
|
}
|
||||||
content += '\n';
|
content += '\n';
|
||||||
});
|
});
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user