Skip to content

Commit

Permalink
Experimental tutorial preset
Browse files Browse the repository at this point in the history
  • Loading branch information
khromov committed Dec 3, 2024
1 parent f45ff16 commit b201f9a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
40 changes: 38 additions & 2 deletions src/lib/fetchMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export interface MinimizeOptions {
removeNoteBlocks?: boolean
removeDetailsBlocks?: boolean
removeHtmlComments?: boolean
removeDiffMarkers?: boolean // New option for removing diff markers
}

const defaultOptions: MinimizeOptions = {
Expand All @@ -149,7 +150,8 @@ const defaultOptions: MinimizeOptions = {
removePrettierIgnore: true,
removeNoteBlocks: true,
removeDetailsBlocks: true,
removeHtmlComments: false
removeHtmlComments: false,
removeDiffMarkers: true // Enable by default
}

function removeQuoteBlocks(content: string, blockType: string): string {
Expand All @@ -175,12 +177,46 @@ function removeQuoteBlocks(content: string, blockType: string): string {
.join('\n')
}

function removeDiffMarkersFromContent(content: string): string {
let inCodeBlock = false
const lines = content.split('\n')
const processedLines = lines.map((line) => {
// Track if we're entering or leaving a code block
if (line.trim().startsWith('```')) {
inCodeBlock = !inCodeBlock
return line
}

// Only process lines within code blocks
if (inCodeBlock) {
// Handle lines that start with --- or +++ with possible whitespace before
line = line.replace(/^[\s]*(\+{3}|\-{3})/g, '')
// Handle lines that end with --- or +++ with possible whitespace after
line = line.replace(/(\+{3}|\-{3})[\s]*$/g, '')

// Handle single + or - markers at start of lines with possible whitespace
line = line.replace(/^[\s]*[\+\-][\s]/g, '')

// Handle multi-line diff blocks where --- or +++ might be in the middle of the line
line = line.replace(/[\s]*(\+{3}|\-{3})[\s]*/g, '')
}

return line
})

return processedLines.join('\n')
}

function minimizeContent(content: string, options?: Partial<MinimizeOptions>): string {
// Merge with defaults, but only for properties that are defined
const settings: MinimizeOptions = options ? { ...defaultOptions, ...options } : defaultOptions

let minimized = content

if (settings.removeDiffMarkers) {
minimized = removeDiffMarkersFromContent(minimized)
}

if (settings.removeLegacy) {
minimized = removeQuoteBlocks(minimized, 'LEGACY')
}
Expand Down Expand Up @@ -223,4 +259,4 @@ function minimizeContent(content: string, options?: Partial<MinimizeOptions>): s
}

return minimized
}
}
16 changes: 16 additions & 0 deletions src/lib/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ export const presets: Record<string, PresetConfig> = {
removeHtmlComments: true
}
},
'svelte-small-experimental': {
title: 'Svelte + SvelteKit (Small Experimental)',
owner: 'sveltejs',
repo: 'svelte.dev',
glob: ['**/apps/svelte.dev/content/tutorial/**/*.md'],
ignore: [
],
prompt: 'Always use Svelte 5 runes. Runes do not need to be imported, they are globals.',
minimize: {
//removeLegacy: true,
//removePlaygroundLinks: true,
//removeNoteBlocks: true,
//removeDetailsBlocks: true,
//removeHtmlComments: true
}
},
sveltekit: {
title: 'SvelteKit',
owner: 'sveltejs',
Expand Down

0 comments on commit b201f9a

Please sign in to comment.