mirror of
https://github.com/Ionaru/easy-markdown-editor
synced 2025-07-22 17:34:37 -06:00
WIP : Refactoring ajout multi-lignes
This commit is contained in:
parent
1b98dd833e
commit
f798a4e9d8
@ -13,11 +13,7 @@
|
||||
<body>
|
||||
<textarea></textarea>
|
||||
<script>
|
||||
const easyMDE = new EasyMDE({
|
||||
parsingConfig: {
|
||||
headingLevels: [ 5, 2, 3, 5 ]
|
||||
}
|
||||
});
|
||||
const easyMDE = new EasyMDE();
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
27
example/index_parsingConfig_headingLevels.html
Normal file
27
example/index_parsingConfig_headingLevels.html
Normal file
@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Example / Preview / parsingConfig / headingLevels</title>
|
||||
<link rel="stylesheet" href="../dist/easymde.min.css">
|
||||
<script src="../dist/easymde.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<textarea>## Lorem Ipsum
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. **Aliquam odio enim**, porta in odio eu, posuere blandit ipsum. Donec non eleifend nulla. Nullam mattis viverra tortor in rutrum. Phasellus non auctor dolor, laoreet aliquam purus. Pellentesque eget tempus sem, et tempus neque. *Etiam fringilla id odio nec feugiat*.
|
||||
Quisque vitae orci eget quam auctor bibendum. Donec dapibus libero non tortor condimentum, **sed lobortis quam tempor**. Morbi purus nisi, maximus ac libero sed, sollicitudin dictum mi. Ut nibh quam, efficitur vel vulputate quis, efficitur nec dui. Ut ut ultricies eros. Pellentesque et nisl at augue ullamcorper tempor. Cras quam risus, commodo a interdum in, vestibulum a ligula. Vestibulum et aliquam nulla.
|
||||
### Dolor Sit Amet</textarea>
|
||||
<script>
|
||||
const easyMDE = new EasyMDE({
|
||||
parsingConfig: {
|
||||
headingLevels: [ 5, 2, 3, 5 ]
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -2520,43 +2520,52 @@ EasyMDE.prototype.render = function (el) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Multilines modification like a paste
|
||||
if (!/delete/.test(obj.origin)) {
|
||||
if (obj.text.length < 2 && obj.text[0].length < 2) {
|
||||
return false;
|
||||
}
|
||||
// Multilines modification like a paste
|
||||
var r;
|
||||
if (obj.from.ch === 0) {
|
||||
// Loop each row and check for headers
|
||||
for (r=0; r<obj.text.length; r++) {
|
||||
obj.text[r] = headingCheckRow(obj.text[r], cm);
|
||||
}
|
||||
var r = 0, rEnd = obj.text.length; // Start row / End row
|
||||
if (obj.from.ch > 7) {
|
||||
// We are sure an new heading is not involved or conflicting with an existing one
|
||||
// So we can safely exclude the first row from the verification loop
|
||||
r = 1;
|
||||
}
|
||||
else if (obj.from.ch > 7) {
|
||||
// We are sure an new heading is not involved with conflicting an existing one
|
||||
// So we can safely exclude the first row from the loop
|
||||
for (r=1; r<obj.text.length; r++) {
|
||||
obj.text[r] = headingCheckRow(obj.text[r], cm);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// We need to check the first row in case an existing heading exists or is updated
|
||||
var startText, oldText, newText;
|
||||
for (r=0; r<obj.text.length; r++) {
|
||||
if (!r) { // First row
|
||||
startText = cm.getRange({line: obj.from.line, ch: 0}, {line: obj.from.line, ch: obj.from.ch});
|
||||
if (/#/.test(startText)) {
|
||||
oldText = startText + obj.text[r];
|
||||
while (r < rEnd) {
|
||||
if (!r && obj.from.ch > 0) {
|
||||
// We need to check the first row in case an existing heading exists or is updated
|
||||
var startText = cm.getRange({
|
||||
line: obj.from.line,
|
||||
ch: 0,
|
||||
}, {
|
||||
line: obj.from.line,
|
||||
ch: obj.from.ch,
|
||||
});
|
||||
if (/#/.test(startText)) {
|
||||
var oldText = startText + obj.text[r],
|
||||
newText = headingCheckRow(oldText, cm);
|
||||
if (oldText !== newText) { // A modification has been made
|
||||
obj.text[r] = newText;
|
||||
obj.from.ch = 0;
|
||||
}
|
||||
if (oldText !== newText) { // A modification has been made
|
||||
obj.text[r] = newText.substring(obj.from.ch);
|
||||
// obj.from.ch = 0;
|
||||
}
|
||||
} else { // 2nd and next rows
|
||||
obj.text[r] = headingCheckRow(obj.text[r], cm);
|
||||
}
|
||||
}
|
||||
else if (r === rEnd - 1) {
|
||||
var endText = cm.getRange({
|
||||
line: obj.from.line,
|
||||
ch: obj.from.ch,
|
||||
}, {
|
||||
line: obj.from.line,
|
||||
ch: obj.from.ch + 8,
|
||||
});
|
||||
console.log( obj.txt[r] );
|
||||
console.log( endText );
|
||||
obj.text[r] = headingCheckRow(obj.text[r], cm);
|
||||
}
|
||||
else { // 2nd and next rows
|
||||
obj.text[r] = headingCheckRow(obj.text[r], cm);
|
||||
}
|
||||
r++;
|
||||
}
|
||||
} else {
|
||||
// Multilines / multicharacters were removed
|
||||
|
Loading…
x
Reference in New Issue
Block a user