mirror of https://github.com/Chocobozzz/PeerTube
Convert markdown to html/plain text for feeds
parent
ebe4b3df5c
commit
228d8e8e47
|
@ -1,5 +1,6 @@
|
||||||
import express from 'express'
|
import express from 'express'
|
||||||
import Feed from 'pfeed'
|
import Feed from 'pfeed'
|
||||||
|
import { mdToPlainText, toSafeHtml } from '@server/helpers/markdown'
|
||||||
import { getServerActor } from '@server/models/application/application'
|
import { getServerActor } from '@server/models/application/application'
|
||||||
import { getCategoryLabel } from '@server/models/video/formatter/video-format-utils'
|
import { getCategoryLabel } from '@server/models/video/formatter/video-format-utils'
|
||||||
import { VideoInclude } from '@shared/models'
|
import { VideoInclude } from '@shared/models'
|
||||||
|
@ -119,7 +120,7 @@ async function generateVideoCommentsFeed (req: express.Request, res: express.Res
|
||||||
title,
|
title,
|
||||||
id: comment.url,
|
id: comment.url,
|
||||||
link,
|
link,
|
||||||
content: comment.text,
|
content: toSafeHtml(comment.text),
|
||||||
author,
|
author,
|
||||||
date: comment.createdAt
|
date: comment.createdAt
|
||||||
})
|
})
|
||||||
|
@ -235,7 +236,7 @@ function initFeed (parameters: {
|
||||||
|
|
||||||
return new Feed({
|
return new Feed({
|
||||||
title: name,
|
title: name,
|
||||||
description,
|
description: mdToPlainText(description),
|
||||||
// updated: TODO: somehowGetLatestUpdate, // optional, default = today
|
// updated: TODO: somehowGetLatestUpdate, // optional, default = today
|
||||||
id: webserverUrl,
|
id: webserverUrl,
|
||||||
link: webserverUrl,
|
link: webserverUrl,
|
||||||
|
@ -298,8 +299,8 @@ function addVideosToFeed (feed, videos: VideoModel[]) {
|
||||||
title: video.name,
|
title: video.name,
|
||||||
id: video.url,
|
id: video.url,
|
||||||
link: WEBSERVER.URL + video.getWatchStaticPath(),
|
link: WEBSERVER.URL + video.getWatchStaticPath(),
|
||||||
description: video.getTruncatedDescription(),
|
description: mdToPlainText(video.getTruncatedDescription()),
|
||||||
content: video.description,
|
content: toSafeHtml(video.description),
|
||||||
author: [
|
author: [
|
||||||
{
|
{
|
||||||
name: video.VideoChannel.Account.getDisplayName(),
|
name: video.VideoChannel.Account.getDisplayName(),
|
||||||
|
|
|
@ -10,7 +10,7 @@ const markdownIt = new MarkdownItClass('default', { linkify: true, breaks: true,
|
||||||
markdownIt.enable(TEXT_WITH_HTML_RULES)
|
markdownIt.enable(TEXT_WITH_HTML_RULES)
|
||||||
markdownIt.use(markdownItEmoji)
|
markdownIt.use(markdownItEmoji)
|
||||||
|
|
||||||
const toSafeHtml = text => {
|
const toSafeHtml = (text: string) => {
|
||||||
if (!text) return ''
|
if (!text) return ''
|
||||||
|
|
||||||
// Restore line feed
|
// Restore line feed
|
||||||
|
@ -23,7 +23,7 @@ const toSafeHtml = text => {
|
||||||
return sanitizeHtml(html, sanitizeOptions)
|
return sanitizeHtml(html, sanitizeOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
const mdToPlainText = text => {
|
const mdToPlainText = (text: string) => {
|
||||||
if (!text) return ''
|
if (!text) return ''
|
||||||
|
|
||||||
// Convert possible markdown (emojis, emphasis and lists) to html
|
// Convert possible markdown (emojis, emphasis and lists) to html
|
||||||
|
|
|
@ -274,8 +274,8 @@ describe('Test syndication feeds', () => {
|
||||||
|
|
||||||
const jsonObj = JSON.parse(json)
|
const jsonObj = JSON.parse(json)
|
||||||
expect(jsonObj.items.length).to.be.equal(2)
|
expect(jsonObj.items.length).to.be.equal(2)
|
||||||
expect(jsonObj.items[0].html_content).to.equal('super comment 2')
|
expect(jsonObj.items[0].html_content).to.contain('<p>super comment 2</p>')
|
||||||
expect(jsonObj.items[1].html_content).to.equal('super comment 1')
|
expect(jsonObj.items[1].html_content).to.contain('<p>super comment 1</p>')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue