mirror of
https://github.com/codex-team/editor.js
synced 2024-06-05 23:42:20 +02:00
new method for paragraph parser
made new method that parses content UL won’t we passed from sanitize
This commit is contained in:
parent
1caaaeaaf0
commit
119f7b7ec7
|
@ -1831,6 +1831,69 @@ var codex =
|
|||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* @public
|
||||
*
|
||||
* @param [String] htmlString - html content as string
|
||||
* @return {string} - html content as string
|
||||
*/
|
||||
content.makeParagraphsFromContent = function (htmlString) {
|
||||
|
||||
var wrapper = document.createElement('DIV'),
|
||||
newWrapper = document.createElement('DIV'),
|
||||
i,
|
||||
paragraph,
|
||||
firstLevelBlocks = ['DIV', 'BLOCKQUOTE', 'SECTION', 'ARTICLE', 'PRE', 'CODE', 'P'],
|
||||
blockTyped,
|
||||
node;
|
||||
|
||||
wrapper.innerHTML = htmlString;
|
||||
paragraph = document.createElement('P');
|
||||
|
||||
for (i = 0; i < wrapper.childNodes.length; i++) {
|
||||
|
||||
node = wrapper.childNodes[i];
|
||||
blockTyped = firstLevelBlocks.indexOf(node.tagName) != -1;
|
||||
|
||||
// console.log("Узел: %o", node);
|
||||
// console.log(blockTyped ? 'Он блочный' : 'Инлайновый');
|
||||
|
||||
if (blockTyped) {
|
||||
|
||||
// console.log('Проверим, не сформировали ли мы до этого параграф из инлайновых элементов');
|
||||
// console.log('Длина контента параграфа: ', paragraph.textContent.length);
|
||||
|
||||
if (paragraph.childNodes.length) {
|
||||
|
||||
// console.info('Опа, параграф не пустой. Нужно его добавить и очистить');
|
||||
// console.log('Клонировали, добавили');
|
||||
|
||||
newWrapper.appendChild(paragraph.cloneNode(true));
|
||||
|
||||
paragraph = null;
|
||||
paragraph = document.createElement('P');
|
||||
}
|
||||
|
||||
newWrapper.appendChild(node.cloneNode(true));
|
||||
} else {
|
||||
|
||||
// console.log('Инлайновые элементы мы добавляем в парагаф');
|
||||
// console.log('Сейчас в нем %o детей', paragraph.childNodes.length);
|
||||
|
||||
paragraph.appendChild(node.cloneNode(true));
|
||||
|
||||
// console.log('А теперь: %o', paragraph.childNodes.length);
|
||||
// console.log('Проверим, не последний ли это элемент. Если да, то параграф нужно добавить в обертку перед выходом из цикла');
|
||||
|
||||
if (i == wrapper.childNodes.length - 1) {
|
||||
newWrapper.appendChild(paragraph);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return newWrapper.innerHTML;
|
||||
};
|
||||
|
||||
return content;
|
||||
}({});
|
||||
|
||||
|
@ -4404,7 +4467,6 @@ var codex =
|
|||
target: '_blank',
|
||||
rel: 'nofollow'
|
||||
},
|
||||
ul: {},
|
||||
i: {},
|
||||
b: {},
|
||||
strong: {},
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -51,7 +51,7 @@
|
|||
<script>
|
||||
codex.start({
|
||||
textareaId : "codex_area",
|
||||
initialBlockPlugin : 'paragraph',
|
||||
initialBlockPlugin : 'quote_styled',
|
||||
tools : {
|
||||
paragraph: {
|
||||
type: 'paragraph',
|
||||
|
|
|
@ -698,6 +698,72 @@ var content = (function(content) {
|
|||
|
||||
};
|
||||
|
||||
/**
|
||||
* @public
|
||||
*
|
||||
* @param [String] htmlString - html content as string
|
||||
* @return {string} - html content as string
|
||||
*/
|
||||
content.makeParagraphsFromContent = function(htmlString) {
|
||||
|
||||
var wrapper = document.createElement('DIV'),
|
||||
newWrapper = document.createElement('DIV'),
|
||||
i,
|
||||
paragraph,
|
||||
firstLevelBlocks = ['DIV', 'BLOCKQUOTE', 'SECTION', 'ARTICLE', 'PRE', 'CODE', 'P'],
|
||||
blockTyped,
|
||||
node;
|
||||
|
||||
wrapper.innerHTML = htmlString;
|
||||
paragraph = document.createElement('P');
|
||||
|
||||
for (i = 0; i < wrapper.childNodes.length; i++) {
|
||||
|
||||
node = wrapper.childNodes[i];
|
||||
blockTyped = firstLevelBlocks.indexOf(node.tagName) != -1;
|
||||
|
||||
// console.log("Узел: %o", node);
|
||||
// console.log(blockTyped ? 'Он блочный' : 'Инлайновый');
|
||||
|
||||
if ( blockTyped ) {
|
||||
|
||||
// console.log('Проверим, не сформировали ли мы до этого параграф из инлайновых элементов');
|
||||
// console.log('Длина контента параграфа: ', paragraph.textContent.length);
|
||||
|
||||
if ( paragraph.childNodes.length ){
|
||||
|
||||
// console.info('Опа, параграф не пустой. Нужно его добавить и очистить');
|
||||
// console.log('Клонировали, добавили');
|
||||
|
||||
newWrapper.appendChild(paragraph.cloneNode(true));
|
||||
|
||||
paragraph = null;
|
||||
paragraph = document.createElement('P');
|
||||
|
||||
}
|
||||
|
||||
newWrapper.appendChild(node.cloneNode(true));
|
||||
|
||||
} else {
|
||||
|
||||
// console.log('Инлайновые элементы мы добавляем в парагаф');
|
||||
// console.log('Сейчас в нем %o детей', paragraph.childNodes.length);
|
||||
|
||||
paragraph.appendChild(node.cloneNode(true));
|
||||
|
||||
// console.log('А теперь: %o', paragraph.childNodes.length);
|
||||
// console.log('Проверим, не последний ли это элемент. Если да, то параграф нужно добавить в обертку перед выходом из цикла');
|
||||
|
||||
if ( i == wrapper.childNodes.length - 1 ){
|
||||
newWrapper.appendChild(paragraph);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return newWrapper.innerHTML;
|
||||
|
||||
};
|
||||
|
||||
return content;
|
||||
|
||||
})({});
|
||||
|
|
|
@ -20,7 +20,6 @@ var sanitizer = (function(sanitizer) {
|
|||
target: '_blank',
|
||||
rel: 'nofollow'
|
||||
},
|
||||
ul: {},
|
||||
i: {},
|
||||
b: {},
|
||||
strong: {},
|
||||
|
|
|
@ -440,52 +440,12 @@ var quote = (function(quote) {
|
|||
|
||||
var prepareDataForSave_ = function(data) {
|
||||
|
||||
var nodeTypeTag = 1,
|
||||
wrapper = document.createElement('DIV'),
|
||||
child,
|
||||
paragraph,
|
||||
nodeIsTag,
|
||||
nodeIsParagraphTag;
|
||||
|
||||
|
||||
if (data.size == 'withPhoto') {
|
||||
data.size = 'small';
|
||||
}
|
||||
|
||||
wrapper.innerHTML = data.text;
|
||||
|
||||
|
||||
for (child = 0; child < wrapper.childNodes.length; child++) {
|
||||
|
||||
console.log("node: %o", wrapper.childNodes[child]);
|
||||
|
||||
nodeIsTag = wrapper.childNodes[child].nodeType == nodeTypeTag;
|
||||
nodeIsParagraphTag = wrapper.childNodes[child].tagName == 'P';
|
||||
|
||||
console.log("nodeIsTag: %o", nodeIsTag);
|
||||
console.log("nodeIsParagraphTag: %o", nodeIsParagraphTag);
|
||||
|
||||
/**
|
||||
* Wrapp all Text nodes and not-paragraph tags in <p>
|
||||
*/
|
||||
if ( !nodeIsTag || !nodeIsParagraphTag ) {
|
||||
|
||||
console.log("Wrapping...");
|
||||
|
||||
paragraph = document.createElement('P');
|
||||
paragraph.innerHTML = wrapper.childNodes[child].innerHTML || wrapper.childNodes[child].textContent;
|
||||
|
||||
console.log("paragraph: %o", paragraph);
|
||||
|
||||
wrapper.childNodes[child].replaceWith(paragraph);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
console.log("wrapper.children: %o", wrapper.children);
|
||||
|
||||
data.text = wrapper.innerHTML;
|
||||
/** Make paragraphs */
|
||||
data.text = codex.content.makeParagraphsFromContent(data.text);
|
||||
|
||||
return data;
|
||||
};
|
||||
|
@ -518,7 +478,7 @@ var quote = (function(quote) {
|
|||
*/
|
||||
var parsedblock = methods_.parseBlockQuote(blockContent);
|
||||
|
||||
var data = {
|
||||
var outputData = {
|
||||
"text" : parsedblock.text,
|
||||
"format" : "html",
|
||||
"cite" : parsedblock.author,
|
||||
|
@ -527,7 +487,7 @@ var quote = (function(quote) {
|
|||
"image" : parsedblock.photo
|
||||
};
|
||||
|
||||
return prepareDataForSave_(data);
|
||||
return prepareDataForSave_(outputData);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue