-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
50 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { withLineNumbers } from 'codejar/linenumbers'; | ||
import Prism from 'prismjs'; | ||
import 'prismjs/plugins/normalize-whitespace/prism-normalize-whitespace'; | ||
|
||
export function useLineNumbers(color: string = '#C9BFBF'): (editor: HTMLElement) => void { | ||
return withLineNumbers(Prism.highlightElement, { | ||
color, | ||
}); | ||
} | ||
|
||
/** Normalize lines indents. */ | ||
export function normalize(markup: string): string { | ||
return Prism.plugins.NormalizeWhitespace.normalize(markup); | ||
} | ||
|
||
/** Wrap long markup lines. */ | ||
export function wrapLines(markup: string, wrapThreshold: number = 60) : string { | ||
const lines: string[] = []; | ||
|
||
for (const line of markup.split('\n')) { | ||
if (line.length < wrapThreshold) { | ||
lines.push(line); | ||
} else { | ||
for (let splitPos = 0; splitPos < line.length; splitPos += wrapThreshold) { | ||
lines.push(line.substring(splitPos, splitPos + wrapThreshold)); | ||
} | ||
} | ||
} | ||
|
||
return lines.join('\n'); | ||
} |