diff --git a/news_parser.js b/news_parser.js index 49f8fff..e49f5bb 100644 --- a/news_parser.js +++ b/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 + ''; - } - 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 += '
  • ' + GrubTextFuncTemplate()(c) + '
  • '; + } + a_Content = ''; + } + + if (a_OutTag && a_TextAlign) { + a_Content = '<' + a_OutTag + ' style = "text-align:' + a_TextAlign + ';">' + a_Content + ''; + } + if (a_Element && a_Element.dataset && a_Element.dataset.type == 'quote') { + a_Content = '
    ' + a_Content + '
    '; + } + + 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; }