From 4b3f914105b53a1b85d7aa1b0ecc3bb7c59e886a Mon Sep 17 00:00:00 2001 From: juangpc Date: Fri, 2 Apr 2021 15:56:36 -0400 Subject: [PATCH] parsinglists not working --- tools/python/demo_recursive_folder_process.py | 16 +-- tools/python/documentation_pdf_generator.py | 90 +++++++++++++++-- tools/python/list_trash_text1.txt | 15 +++ tools/python/list_trash_text2.txt | 26 +++++ .../mne_cpp/__pycache__/core.cpython-39.pyc | Bin 7099 -> 7038 bytes .../__pycache__/pdf_doc.cpython-39.pyc | Bin 6805 -> 11782 bytes tools/python/mne_cpp/core.py | 2 +- tools/python/mne_cpp/pdf_doc.py | 95 +++++++++++++----- 8 files changed, 198 insertions(+), 46 deletions(-) create mode 100644 tools/python/list_trash_text1.txt create mode 100644 tools/python/list_trash_text2.txt diff --git a/tools/python/demo_recursive_folder_process.py b/tools/python/demo_recursive_folder_process.py index 08ed3d51e3b..126d2cdf37d 100644 --- a/tools/python/demo_recursive_folder_process.py +++ b/tools/python/demo_recursive_folder_process.py @@ -1,18 +1,18 @@ -import mne_cpp.core +import mne_cpp.core as mne # import mne_cpp.pdf_doc from os import stat -mne_cpp.core.version() +mne.version() -projectFolder = mne_cpp.core.baseFolder() +projectFolder = mne.baseFolder() # Recursively list all the files in a directory and order by size and print results. listOfFiles = [] -mne_cpp.core.recursiveFolderProcess(projectFolder + 'doc/gh-pages', lambda f: \ - listOfFiles.append((f, stat(f).st_size)) \ - if f.name.endswith('.md') \ - else None ) +mne.recursiveFolderProcess(projectFolder + 'doc/gh-pages', lambda f: \ + listOfFiles.append((f, stat(f).st_size)) \ + if f.name.endswith('.md') \ + else None ) listOfFiles.sort(reverse=True, key=lambda f:f[1]) for f in listOfFiles: - print('File: ' + f[0].path + ' - (' + mne_cpp.core.sizeHumanReadable(f[1]) + ')') + print('File: ' + f[0].path + ' - (' + mne.sizeHumanReadable(f[1]) + ')') diff --git a/tools/python/documentation_pdf_generator.py b/tools/python/documentation_pdf_generator.py index dfdbb1a2428..9c1844f1df5 100644 --- a/tools/python/documentation_pdf_generator.py +++ b/tools/python/documentation_pdf_generator.py @@ -1,25 +1,93 @@ import mne_cpp.core -import mne_cpp.pdf_doc +import mne_cpp.pdf_doc as mnepdf projectFolder = mne_cpp.core.baseFolder() webBaseFolder = projectFolder + 'doc/gh-pages' -# webDocuments = mne_cpp.pdf_doc.scanFolder(webBaseFolder) +# webDocuments = mnepdf.scanFolder(webBaseFolder) # print(webDocuments) -# web = mne_cpp.pdf_doc.buildWebStructure(webDocuments) +# web = mnepdf.buildWebStructure(webDocuments) # print('Printing Web Structure:') # print(web) # (pathLabel, filePath, fileName, fileExt, fullPath) = mne_cpp.core.extractFilePaths('../../doc/gh-pages/pages/documentation/anonymize.md') -(pathLabel, filePath, fileName, fileExt, fullPath) = mne_cpp.core.extractFilePaths('../../doc/gh-pages/pages/contact.md') +# (pathLabel, filePath, fileName, fileExt, fullPath) = mne_cpp.core.extractFilePaths('../../doc/gh-pages/pages/contact.md') + +# inFile = open(fullPath, mode = 'r', encoding = 'utf8') +# inText = inFile.read() +# inFile.close() + +# outText = mnepdf.parseUnorderedList(inText) +# outFile = open(pathLabel + filePath + fileName + '.PROCESSED' + '.' + fileExt, mode = 'w', encoding = 'utf8') +# outFile.write(outText) +# outFile.close() + +inText = r''' +--- +layout: default +title: Markdown kitchen sink +nav_order: 99 +--- +(\n(( *[-*] *)|(\s*\d+\.\s*))[^\-*\n ].+)+ +(\n(( *[-*] *)|( *\d+\. *))[^\-*\n ].+)+ +(\n(( *[-*] *)|( *\d+\. *))[^\-*\n ].+)+ +Text can be **bold**, _italic_, or ~~strikethrough~~. + +[Link to another page](another-page). + +There should be whitespace between paragraphs. + +There should be whitespace between paragraphs. We recommend including a README, or a file with information about your project. + +# [](#header-1)Header 1 + +This is a normal paragraph following a header. GitHub is a code hosting platform for version control and collaboration. It lets you and others work together on projects from anywhere. + +## [](#header-2)Header 2 + +> This is a blockquote following a header. +> +> When something is important enough, you do it even if the odds are not in your favor. + +### [](#header-3)Header 3 + +```js +// Javascript code with syntax highlighting. +var fun = function lang(l) { + dateformat.i18n = require('./lang/' + l) + return true; +} +``` + +```ruby +# Ruby code with syntax highlighting +GitHubPages::Dependencies.gems.each do |gem, version| + s.add_dependency(gem, "= #{version}") +end +``` +- level 1 item + - level 2 item + - level 2 item + - level 3 item + - level 3 item +- level 1 item + - level 2 item + - level 2 item + - level 2 item +- level 1 item + - level 2 item + - level 2 item +- level 1 item +''' + +outText = mnepdf.parseLists(inText) + + + + + +a = 3 -inFile = open(fullPath, mode = 'r', encoding = 'utf8') -inText = inFile.read() -inFile.close() -outText = mne_cpp.pdf_doc.parseUnorderedList(inText) -outFile = open(pathLabel + filePath + fileName + '.PROCESSED' + '.' + fileExt, mode = 'w', encoding = 'utf8') -outFile.write(outText) -outFile.close() diff --git a/tools/python/list_trash_text1.txt b/tools/python/list_trash_text1.txt new file mode 100644 index 00000000000..b8722d23132 --- /dev/null +++ b/tools/python/list_trash_text1.txt @@ -0,0 +1,15 @@ +\begin{itemize} + \item level 1 item + - level 2 item + - level 2 item + - level 3 item + - level 3 item + \item level 1 item + - level 2 item + - level 2 item + - level 2 item + \item level 1 item + - level 2 item + - level 2 item + \item level 1 item +\end{itemize} \ No newline at end of file diff --git a/tools/python/list_trash_text2.txt b/tools/python/list_trash_text2.txt new file mode 100644 index 00000000000..dd5efdd10d0 --- /dev/null +++ b/tools/python/list_trash_text2.txt @@ -0,0 +1,26 @@ +\begin{itemize} + \item level 1 item + \begin{itemize} + \item level 2 item + \item level 2 item + \begin{itemize} + \item level 3 item + \item level 3 item + \end{itemize} + \end{itemize} + \item level 1 item + \begin{itemize} + \item level 2 item + \item level 2 item + \item level 2 item + \end{itemize} + \item level 1 item + \begin{itemize} + \item level 2 item + \item level 2 item + \end{itemize} + \item level 1 item +\end{itemize} + + + \ No newline at end of file diff --git a/tools/python/mne_cpp/__pycache__/core.cpython-39.pyc b/tools/python/mne_cpp/__pycache__/core.cpython-39.pyc index 3f726fee9fcfd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cY?3ZqW2YMLj9sryr?*%5{38<|}I@7t?Oe%lSw_ zE8g-!3b?8sRstIZN4`>jSC%d9siUdJVOtM*z4SFTm3Ppjre;8(n2>}H$Pwjq8Zk1s zaX`8GgE1i78eq0aR>(9-%mJ;ECkAT8-Z;~24v)8=eY8|x>>kWLI)Dl$QAlPGC19hU zW;*dU;MLPCll@L7cp#)}q?Qc!MQX>ON&QbES{>=6uCd*I&yN@gpZhzZ_z??3wGea4 zf=zt5qPkOc>4vguE)r9(m1(LztIZw$f}OC6us`1w2@3<6u(-oIC~R5(G>qGRC|A(& zdpq1;aZv@>>rxNTIeg*aVYc;<;bA8JH{>bSq$ZG{a4%D6q34z%k6UWQ>Upg~udA1} z*@jj*ysx35LI3Am9n0F&j|2BKY--R`)TU8VThpU&&tc%u@u5=lmSZ`llNq;07o1Dz LRh(IeI@x~#uEqH% diff --git a/tools/python/mne_cpp/__pycache__/pdf_doc.cpython-39.pyc b/tools/python/mne_cpp/__pycache__/pdf_doc.cpython-39.pyc index 19de6703c4abcaad489b4e8b32034bf960b4196b..d56980db3f2cefc70b9b7a71cec8ca9d8ca9c2bd 100644 GIT binary patch literal 11782 zcmb7K+ix7#d7sC8}<;cl8%X$ll@;s$71^b(Lwkj8mx^HQLX{TEsk=%5cp3luR>^rdfX(e(HGW_Gzt z%WkxbIcLuO@_py`UCva;$8!dLD>v6~Zog_6|Hj1d&qm@^JpP<%7|Kv)!zeMf8fMcf zStj4@hTU{ZPBT?XN!o0rOKGW_DY=N9Mz)zN<)kdt7;ENBd3jGa#+wtR3B13oT$TNf zS(;oo)=ZUCV|br>%TReW{vAV&Kd?%NkeX1FNKGO&t)|qW?--@S>WgYx9Y*aLHKUFo z=ZHG0W)UA%$JAqpXVr1_IO1dK3H2o6$JA5mbBK?tf_fV9XXA13qyn>RY+4V@Ub<_&VSH$={G^xZI{r7h znH^iDc1{0Xyg7VR>7$0q+_LpIl-qM|Ki_rqw+6NDeWKR4I09<1pX{!wf6%r4AE2c@ zl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0(SXK3j- zZ%o^)HmP=Gx{M#!gfTs4K{;cU!T1!pO+NyiTTVQ&ye!DzxOgx6$-;W10_|b1jM1D3 zN%wLXvcQylJ5tiYG+xl*?Ed2U!bmn}0M*0RBpr>RQ!kRZ)bY4toWR{LahMu{!onGrSK#G&x8=O#;GRYG+FsEWABavUTyf&F=wM1A+^?8d#Zo-MJ`>-@ zn~uGNdMeR;!AO_*OggU@%6hKPGA>{w6vRk1B8Cg>X=kxynLwEZ7lE6=gHTcRjY*&A zs_*ELjTS|k?F2*Tb|W`(hGiTso7VW8vA>ux4v@4>ChCw_{?ep=DQ1XO1J^S2)Zz1cf;r4VVn48fDr)DpRpS)d$AKzRm&hXG3BK zd45Z^RWR_tDNp0M<3vM`9M&mhyNknA5fla~si4w0`jn1q-~=_^oI=_UII1G2q{xP* z(@z$eMD`z7iA>)9rmK}r?nF{0FliL{#jIuIvlU|=vowuV+ie;;Waey7rkF2b|Jd40 zw!o1KY}YIl%O%@oS~^&^1Et|KiX=TSMUt+(Ze`|DBH5i-m_b6yQ!HEKj|rWGe!^ik zAT0Mf-OypoW)qGcrm0eKhB~79qck~j4B?QMyQO@8Eou5>XRR-2hp6VGK z-7T&*Z#;;7MG?U)0?wyso+qeD>lvi|j-#4ZS|`~E-qf-q>&2bkbqg{#ern=OsnnM# zf&mkxtA~L8bS!`Wxp@D|MRc?e+VDn}ThchUZWto=5Zq{{_R4=rsTU diff --git a/tools/python/mne_cpp/core.py b/tools/python/mne_cpp/core.py index 8f9bffd64d8..c8ee04ae505 100644 --- a/tools/python/mne_cpp/core.py +++ b/tools/python/mne_cpp/core.py @@ -158,8 +158,8 @@ def parseInputArguments(argsToParse, **opts): options[arg_adapted] = argsToParse[arg] return (v for k, v in options.items()) -_suffixes = ['bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'] def sizeHumanReadable(size): + _suffixes = ['bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'] # determine binary order in steps of size 10 # (coerce to int, // still returns a float) order = int(log2(size) / 10) if size else 0 diff --git a/tools/python/mne_cpp/pdf_doc.py b/tools/python/mne_cpp/pdf_doc.py index e6806b234aa..6814f2d2296 100644 --- a/tools/python/mne_cpp/pdf_doc.py +++ b/tools/python/mne_cpp/pdf_doc.py @@ -190,8 +190,14 @@ def parseMarkDownFile(file, **inputArgs): else: with open(file.fullPath, 'r', encoding='utf8') as markDownFile, \ open(texFile,'a+') as texFile: + # The order here is relevant. Some of the regex depend on not having conflicting patterns. + # i.e. empty lines can sometimes interfere with some lists patterns + # i.e.2 horizontal lines (\n* * *) pattern can sometimes be understood as a list. + # I've tried to minimize these conflicts but I'm not 100% sure. So any change should be tested... inText = markDownFile.read() + inText = stripEmptyLines(inText) inText = deleteJustTheDocsHeader(inText) + inText = parseHorizontalLines(inText) inText = parseInlineItalicText(inText) inText = parseInlineBoldText(inText) inText = parseUnorderedList(inText) @@ -211,25 +217,11 @@ def parseInlineItalicText(inText): def parseInlineBoldText(inText): return re.sub(r'(?<=\W)((?P\*\*)|__)(?P[\w ]+)((?(dstar)\*\*)|__)(?=\W)',r'\\textbf{\g}', inText) -def parseUnorderedList(inText): - match = re.search(r'(\n\s?\*\s?.+)(\n\s?\*\s?(.+))*', inText) - if match: - outList = '\n\\begin{itemize}\n' - pattern2 = re.compile(r'\n*\s*\*\s*(?P.+)(?=\n)?') - itemList = pattern2.finditer(match.group(0)) - for item in itemList: - outList += '\t\\item ' + item.group('item') + '\n' - outList += '\\end{itemize}' - outText = inText[:match.start(0)] + outList + inText[match.end(0):] - return parseUnorderedList(outText) - else: - return inText - def parseInlineImages(inText): match = re.search(r'!\[(?P[^]]+)\]\((?P[^)]+)\)', inText) if match: - imgPath = mne_cpp.core.none_if_empty(match.group('imgFilePath')) - imgAltText = mne_cpp.core.none_if_empty(match.group('alt_text')) + imgPath = mne_cpp.core.noneIfEmpty(match.group('imgFilePath')) + imgAltText = mne_cpp.core.noneIfEmpty(match.group('alt_text')) figText = '\n\\begin{wrapfigure}{r}{0.5\\textwidth}' figText += '\n\t\\begin{center}' figText += '\n\t\t\\includegraphics[width=0.4\\textwidth]{ ' + imgPath + '}' @@ -244,7 +236,7 @@ def parseInlineImages(inText): def parseInlineHTMLImages(inText): match = re.search(r'<\s*img\s*src\s*=\s*"(?P[^"]+)".*>', inText) if match: - imgPath = mne_cpp.core.none_if_empty(match.group('imgFilePath')) + imgPath = mne_cpp.core.noneIfEmpty(match.group('imgFilePath')) figText = '\n\\begin{wrapfigure}{r}{0.5\\textwidth}' figText += '\n\t\\begin{center}' figText += '\n\t\t\\includegraphics[width=0.4\\textwidth]{ ' + imgPath + '}' @@ -256,7 +248,7 @@ def parseInlineHTMLImages(inText): else: return inText -def parseTableMd(inText) +def parseTableMd(inText): match = re.search(r'(?<=\n)\|([^|\n]+\|)+', inText) if match: tableText = inText[match.start(0):match.end(0)] @@ -312,14 +304,67 @@ def parseHeaders(inText): else: return inText -def parseHorizontalLine(inText): +def parseHorizontalLines(inText): return re.sub(r'(?<=\n)\*\s\*\s\*(?=\n)','\\noindent\\rule{15cm}{0.5pt}', inText) -# parse horizontal line -# \n\* \* \* +def stripHorizontalLines(inText): + return re.sub(r'(?<=\n)\*\s\*\s\*(?=\n)','', inText) + +def stripEmptyLines(inText): + return re.sub(r'((?<=\n)\n)','',inText) + +# def parseUnorderedList(inText): +# match = re.search(r'(\n\s?\*\s?.+)(\n\s?\*\s?(.+))*', inText) +# if match: +# outList = '\n\\begin{itemize}\n' +# pattern2 = re.compile(r'\n*\s*\*\s*(?P.+)(?=\n)?') +# itemList = pattern2.finditer(match.group(0)) +# for item in itemList: +# outList += '\t\\item ' + item.group('item') + '\n' +# outList += '\\end{itemize}' +# outText = inText[:match.start(0)] + outList + inText[match.end(0):] +# return parseUnorderedList(outText) +# else: +# return inText +def parseUnorderedList(inText, i): + pattern = r'\n(( {0}[-*] *)(?P.*))' + lastMatch = len(re.findall(pattern, inListText)) + matches = re.finditer(pattern, inListText) + parsedText = '' + for numMatch, match in enumerate(matches, start = 1): + itemText = '\n\\begin{itemize}' if numMatch is 1 else '' + itemText += '\\item ' + match.group('itemText') + itemText += '\\end{itemize}' if numMatch is lastMatch + parsedText += inListText[:match.start()] + itemText + inListText[match.end():] + + +def parseOneList(inList): + outList = parseUnorderedList(inList) + + + +def parseLists(inText): + match = re.search(r'(\n(( *[-*] *)|( *\d+\. *))[^\-*\n ].+)+', inText) + if match: + parsedList = parseOneList(match.group()) + outText = inText[:match.start()] + parsedList + inText[match.end():] + return parseLists + else: + return inText + + + # for spaces in range(2:2:6): + # pattern = + +# matches4ord = re.finditer(r'(\n( {2}(\d+\.) *)([^-\n ].*))+', text[match.start(0):match.end(0)]) +# for match4ord in matches4ord: +# outText = '\n\\begin{enumerate}\n' + +# ((\n {2}\d+\. *)(?P.*)) # parse all lists with (\n((\s*[-*]\s*)|(\s*\d+\.\s*)).+)+ -# see https://regex101.com/r/2uKqPB/1/ +# https://regex101.com/r/idzIo5/1/ +# https://regex101.com/r/Iu3hKt/1 # after this parse # ordered lists of level 4 @@ -335,18 +380,16 @@ def parseHorizontalLine(inText): # https://tex.stackexchange.com/questions/247681/how-to-create-checkbox-todo-list - - # still missing: # ordered and unordered lists parsing # inbound links vs outbound links # parse inline code # preamble and ending file # parse multiple terms description/definition - +# header tags up to 6 #s def processImage(imageFile): - _, _, _, _, fileExt = mne_cpp.core.parseFilePathNameExt(imageFile) + _, _, _, _, fileExt = mne_cpp.core.parseFilePathNameExt(imageFile) if fileExt == "jpg" or fileExt == "jpeg": jpg2png(imageFile) if fileExt == "svg2":