Skip to content

Commit 295e8e6

Browse files
committed
minor cleanup of the client-side stripMarkdown helper
1 parent e94b45a commit 295e8e6

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

app/assets/javascripts/character_count.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ $(() => {
6767

6868
const fullCount = $tgt.val().trim().length;
6969
const count = omitMarkdown ?
70-
QPixel.MD.stripMarkdown($tgt.val().trim(), { removeQuotes: true }).length :
70+
QPixel.MD.stripMarkdown($tgt.val().trim(), { removeLeadingQuote: true }).length :
7171
fullCount;
7272

7373
$info.toggleClass('hide', fullCount === count)

app/assets/javascripts/qpixel_markdown.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ QPixel.MD = {
77
.replace(/[*_~]+/g, '')
88
.replace(/!?\[([^\]]+)\](?:\([^)]+\)|\[[^\]]+\])/g, '$1');
99

10-
if (options.removeQuotes) {
10+
if (options.removeLeadingQuote ?? false) {
1111
return stripped.replace(/^>.+?$/g, '');
1212
}
1313

global.d.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,19 @@ interface QPixelDOM {
3737
setVisible?: (elements: HTMLElement | HTMLElement[], visible: boolean) => void;
3838
}
3939

40+
interface StripMarkdownOptions {
41+
/**
42+
* Whether to strip away the leading quote ("> content"), if any
43+
* @default false
44+
*/
45+
removeLeadingQuote?: boolean
46+
}
47+
4048
interface QPixelMD {
4149
/**
42-
* See [strip_markdown](./app/helpers/application_helper.rb) application helper
50+
* See [strip_markdown](app/helpers/application_helper.rb) application helper
4351
*/
44-
stripMarkdown(content: string, options?: {
45-
removeQuotes?: boolean
46-
}): string;
52+
stripMarkdown(content: string, options?: StripMarkdownOptions): string;
4753
}
4854

4955
type QPixelKeyboardState =

0 commit comments

Comments
 (0)