Skip to content

Commit 41e5d8c

Browse files
committed
+ ISSUE-46 Code blocks and block italic-bold issue.
1 parent a392968 commit 41e5d8c

File tree

10 files changed

+35
-15
lines changed

10 files changed

+35
-15
lines changed

.npmignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
docs
2+
.cache
3+
.github
4+
tests

dist/quilljs-markdown.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/quilljs-markdown.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/bundle/demojs.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/bundle/demojs.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/demo.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import Quill from 'quill'
22
import QuillMarkdown from '../src/app'
33

4+
const toolbarOptions = [
5+
['bold', 'italic', 'underline', 'strike'],
6+
[ 'link', 'image'], // add's image support
7+
];
8+
49
const options = {
5-
theme: 'snow'
10+
theme: 'snow',
11+
modules: {
12+
toolbar: toolbarOptions
13+
}
614
}
715

816
document.addEventListener('DOMContentLoaded', () => {

docs/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<meta name="google-site-verification" content="lNpyIBBVvsIatDauJyTfU6q2VtxEMP8npAGigr3gj4Q" />
1313
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/quill.min.js"></script>
1414
<script src="./bundle/demojs.js"></script>
15-
<!-- <script src="./demo.js"></script>-->
15+
<!-- <script src="./demo.js"></script> -->
1616
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/quill.snow.css" rel="stylesheet">
1717
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/kotton-style.min.css">
1818
<link rel="stylesheet" href="../quilljs-markdown-common-style.scss" />

src/app.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class MarkdownActivity {
3737
}
3838

3939
if (!inputText) return
40-
4140
if (inputText.length > 1) {
4241
setTimeout(async () => {
4342
const cursorOffsetFixed = cursorOffset
@@ -51,7 +50,7 @@ class MarkdownActivity {
5150
}
5251
const firstIndex = this.quillJS.getIndex(line)
5352
let _targetText = ''
54-
let result = await this.onFullTextExecute.bind(this)({ index: firstIndex, length: 0 })
53+
let result = await this.onFullTextExecute.bind(this)({ index: firstIndex, delta, length: 0 })
5554

5655
if (result) {
5756
while (result) {
@@ -63,7 +62,7 @@ class MarkdownActivity {
6362
}
6463

6564
_targetText = line.domNode.textContent || ''
66-
result = await this.onFullTextExecute.bind(this)({ index: firstIndex, length: 0 })
65+
result = await this.onFullTextExecute.bind(this)({ index: firstIndex, delta, length: 0 })
6766
}
6867
} else {
6968
_targetText = line.domNode.textContent || ''
@@ -115,14 +114,25 @@ class MarkdownActivity {
115114

116115
async onFullTextExecute (virtualSelection) {
117116
let selection = virtualSelection || this.quillJS.getSelection()
117+
const delta = virtualSelection.delta
118118
if (!selection) return false
119119
const [line, offset] = this.quillJS.getLine(selection.index)
120120

121121
if (!line || offset < 0) return false
122+
const retain = (delta && delta.ops && delta.ops[0].retain) || 0
122123
const lineStart = selection.index - offset
123-
const format = this.quillJS.getFormat(lineStart)
124+
const formatLineStart = retain ? retain - 1 : lineStart
125+
const format = this.quillJS.getFormat(formatLineStart)
124126
if (format['code-block'] || format['code']) {
125127
// if exists text in code-block, to skip.
128+
129+
if (format['code']) {
130+
// ignore all styles when copied text in code block.
131+
const copiedTexts = delta.ops.filter(d => d.insert).map(d => d.insert).join('')
132+
this.quillJS.deleteText(retain, copiedTexts.length)
133+
this.quillJS.insertText(retain, copiedTexts.replace(/\n/g, ''), { code: true })
134+
this.quillJS.format('code', false)
135+
}
126136
return false
127137
}
128138
const beforeNode = this.quillJS.getLine(lineStart - 1)[0]

src/tags/bold/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class Bold extends AbstractTag {
1818
pattern: this.pattern,
1919
action: (text, selection, pattern, lineStart) => new Promise((resolve) => {
2020
let match = pattern.exec(text)
21-
2221
const [annotatedText, , matchedText] = match
2322
const startIndex = lineStart + match.index
2423
if (text.match(/^([*_ \n]+)$/g) || !this.activeTags.length) {

src/tags/italics/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Bold extends AbstractTag {
66
super()
77
this.quillJS = quillJS
88
this.name = 'italic'
9-
this.pattern = this._getCustomPatternOrDefault(options, this.name, /(\*|_){1}(.+?)(?:\1){1}/g)
9+
this.pattern = this._getCustomPatternOrDefault(options, this.name, /(?:^|(?<=\s))(?:(\*|_)\s*(?<text1>[^*_]+)\s*?\1|(\*|_){3}\s*(?<text3>[^*_]*)\s*\1{3})(?:$|(?=\s))/g)
1010
this.getAction.bind(this)
1111
this._meta = meta()
1212
this.activeTags = this._getActiveTagsWithoutIgnore(this._meta.applyHtmlTags, options.ignoreTags)
@@ -18,7 +18,6 @@ class Bold extends AbstractTag {
1818
pattern: this.pattern,
1919
action: (text, selection, pattern, lineStart) => new Promise((resolve) => {
2020
let match = pattern.exec(text)
21-
2221
if (!match || !this.activeTags.length) {
2322
resolve(false)
2423
return

0 commit comments

Comments
 (0)