Skip to content

Commit 08717bc

Browse files
committed
adding back removing non bracking spaces, :emoji: support now also added to changelog markdown rendering
added scroll margin to the changes page
1 parent fbbff33 commit 08717bc

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

app/pages/package-changes/[...path].vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ definePageMeta({
33
name: 'changes',
44
path: '/package-changes/:path+',
55
alias: ['/package/changes/:path+', '/changes/:path+'],
6+
scrollMargin: 130,
67
})
78
89
/// routing

server/utils/changelog/markdown.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { marked, type Tokens } from 'marked'
2-
import { ALLOWED_ATTR, ALLOWED_TAGS, calculateSemanticDepth, prefixId, slugify } from '../readme'
2+
import {
3+
ALLOWED_ATTR,
4+
ALLOWED_TAGS,
5+
calculateSemanticDepth,
6+
prefixId,
7+
slugify,
8+
stripHtmlTags,
9+
} from '../readme'
310
import sanitizeHtml from 'sanitize-html'
411

512
export async function changelogRenderer() {
@@ -86,11 +93,9 @@ export async function changelogRenderer() {
8693
? `user-content-${releaseId}-${uniqueSlug}`
8794
: `user-content-${uniqueSlug}`
8895

89-
// Collect TOC item with plain text (HTML stripped)
90-
const plainText = text
91-
.replace(/<[^>]*>/g, '')
92-
// remove non breaking spaces
93-
.replace(/&nbsp;?/g, '')
96+
// Collect TOC item with plain text (HTML stripped & emoji's added)
97+
const plainText = convertToEmoji(stripHtmlTags(text))
98+
.replace(/&nbsp;?/g, '') // remove non breaking spaces
9499
.trim()
95100
if (plainText) {
96101
toc.push({ text: plainText, id, depth })
@@ -100,9 +105,11 @@ export async function changelogRenderer() {
100105
}
101106

102107
return {
103-
html: marked.parse(markdown, {
104-
renderer,
105-
}) as string,
108+
html: convertToEmoji(
109+
marked.parse(markdown, {
110+
renderer,
111+
}) as string,
112+
),
106113
toc,
107114
}
108115
}

server/utils/readme.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export const ALLOWED_ATTR: Record<string, string[]> = {
179179
* incomplete sanitization from nested/interleaved tags
180180
* (e.g. `<scr<script>ipt>` → `<script>` after one pass).
181181
*/
182-
function stripHtmlTags(text: string): string {
182+
export function stripHtmlTags(text: string): string {
183183
const tagPattern = /<[^>]*>/g
184184
let result = text
185185
let previous: string
@@ -200,7 +200,7 @@ function stripHtmlTags(text: string): string {
200200
*/
201201
export function slugify(text: string): string {
202202
return stripHtmlTags(text)
203-
.toLowerCase()
203+
.replace(/&nbsp;?/g, '') // remove non breaking spaces
204204
.trim()
205205
.replace(/\s+/g, '-') // Spaces to hyphens
206206
.replace(/[^\w\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff-]/g, '') // Keep alphanumeric, CJK, hyphens

0 commit comments

Comments
 (0)