mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
fix: fallback to html if failed to convert html to markdown
This commit is contained in:
parent
87f55eabf6
commit
4cc9547935
2 changed files with 22 additions and 5 deletions
|
|
@ -948,9 +948,13 @@ export const searchResolver = authorized<
|
|||
if (params.includeContent && r.content) {
|
||||
// convert html to the requested format
|
||||
const format = params.format || ArticleFormat.Html
|
||||
const converter = contentConverter(format)
|
||||
if (converter) {
|
||||
r.content = converter(r.content, r.highlights)
|
||||
try {
|
||||
const converter = contentConverter(format)
|
||||
if (converter) {
|
||||
r.content = converter(r.content, r.highlights)
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('Error converting content', error)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -609,11 +609,24 @@ export const htmlToHighlightedMarkdown = (
|
|||
html: string,
|
||||
highlights?: Highlight[]
|
||||
): string => {
|
||||
if (!highlights) {
|
||||
if (!highlights || highlights.length == 0) {
|
||||
return nhm.translate(/* html */ html)
|
||||
}
|
||||
|
||||
let document: Document
|
||||
|
||||
try {
|
||||
document = parseHTML(html).document
|
||||
|
||||
if (!document || !document.documentElement) {
|
||||
// the html is invalid
|
||||
throw new Error('Invalid html content')
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
return nhm.translate(/* html */ html)
|
||||
}
|
||||
|
||||
const document = parseHTML(html).document
|
||||
// wrap highlights in special tags
|
||||
highlights
|
||||
.filter((h) => h.type == 'HIGHLIGHT' && h.patch)
|
||||
|
|
|
|||
Loading…
Reference in a new issue