Browse Source

Цитаты и списки в РИА

master
Alexei 1 year ago
parent
commit
85c1ec5e71
  1. 56
      news_parser.js

56
news_parser.js

@ -60,21 +60,6 @@
return a_String;
}
function FinishWorkFuncTemplate(a_OutTag, a_TextAlign, a_ClearTextFunc) {
function FinishWorkFunc(a_Content, a_Element) {
if (a_ClearTextFunc) {
a_Content = a_ClearTextFunc(a_Content);
}
if (a_OutTag && a_TextAlign) {
return '<' + a_OutTag + ' style = "text-align:' + a_TextAlign + ';">' + a_Content + '</' + a_OutTag + '>';
}
else {
return a_Content;
}
}
return FinishWorkFunc
}
function ClearUrl(a_Url) {
var separator = '?';
return RemoveAfterSplitter(a_Url, separator, false);
@ -162,11 +147,11 @@
}
function ElementCheckerRia(a_Element) {
if (a_Element.dataset.type == 'text' || a_Element.dataset.type == 'quote' || a_Element.dataset.type == 'list') {
return true;
if (a_Element.dataset.type == 'article' || a_Element.dataset.type == 'banner') {
return false;
}
return false;
return true;
}
function ElementCheckerZV(a_Element) {
@ -176,6 +161,8 @@
return false;
}
// Обработка элементов
function GrubTextFuncTemplate() {
function GrubTextFunc(a_Element) {
var content = '';
@ -187,19 +174,46 @@
return GrubTextFunc
}
function FinishWorkFuncTemplate(a_OutTag, a_TextAlign, a_ClearTextFunc) {
function FinishWorkFunc(a_Content, a_Element) {
if (a_ClearTextFunc) {
a_Content = a_ClearTextFunc(a_Content);
}
if (a_Element && a_Element.dataset && a_Element.dataset.type == 'list') {
var childrens = FindElementsByRegExp(GetElementClassName, 'article__list-item', a_Element);
let content = '';
for (let i = 0; i < childrens.length; i++) {
var c = childrens[i];
content += '<li>' + GrubTextFuncTemplate()(c) + '</li>';
}
a_Content = '<ul>' + content + '</ul>';
}
if (a_OutTag && a_TextAlign) {
a_Content = '<' + a_OutTag + ' style = "text-align:' + a_TextAlign + ';">' + a_Content + '</' + a_OutTag + '>';
}
if (a_Element && a_Element.dataset && a_Element.dataset.type == 'quote') {
a_Content = '<blockquote>' + a_Content + '</blockquote>';
}
return a_Content;
}
return FinishWorkFunc
}
// Создание контента для стандартных новостей
function MakeContentByNews(a_BaseElementTitle, a_BaseElementImage, a_BaseElementText, a_TitleRegExpElementPattern, a_ImageRegExpElementPattern, a_TextRegExpElementPattern, a_ElementChecker, a_ClearTextPatterns) {
var title_tag = 'h2';
var p_tag = 'p';
var title_finish_text_func = FinishWorkFuncTemplate(title_tag, 'center')
var grub_text_func = GrubTextFuncTemplate()
var grub_func = GrubTextFuncTemplate();
var content = '';
var paragraph_finish_text_func = FinishWorkFuncTemplate(p_tag, 'justify', ClearTextFuncTemplate(a_ClearTextPatterns));
content += GetContentInContainers(FindElementsByRegExp(GetElementClassName, a_TitleRegExpElementPattern, a_BaseElementTitle), grub_text_func, title_finish_text_func);
content += GetContentInContainers(FindElementsByRegExp(GetElementClassName, a_TitleRegExpElementPattern, a_BaseElementTitle), grub_func, title_finish_text_func);
content += GetImageInContainers(FindElementsByRegExp(GetElementClassName, a_ImageRegExpElementPattern, a_BaseElementImage), 'center');
content += GetContentInContainers(FIlterElements(FindElementsByRegExp(GetElementClassName, a_TextRegExpElementPattern, a_BaseElementText), a_ElementChecker), grub_text_func, paragraph_finish_text_func);
content += GetContentInContainers(FIlterElements(FindElementsByRegExp(GetElementClassName, a_TextRegExpElementPattern, a_BaseElementText), a_ElementChecker), grub_func, paragraph_finish_text_func);
return content;
}

Loading…
Cancel
Save