git @ Cat's Eye Technologies Feedmark / 66bcef2
Implement obtain_heading_text(). Chris Pressey 3 months ago
2 changed file(s) with 17 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
66 import re
77
88 from marko.block import SetextHeading, Heading, HTMLBlock, BlankLine, List, Paragraph, LinkRefDef
9 from marko.inline import Image, Link
9 from marko.inline import Image, Link, RawText, Literal
1010 from marko.parser import Parser as MarkoParser
1111
1212 from .models import Document, Section
5959
6060
6161 def obtain_heading_text(element):
62 # FIXME
63 return element.children[0].children
62 chunks = []
63 for child in element.children:
64 if isinstance(child, RawText):
65 chunks.append(child.children)
66 elif isinstance(child, Literal):
67 chunks.append("\\")
68 chunks.append(child.children)
69 return ''.join(chunks)
6470
6571
6672 class Parser:
8187 reading_properties = True
8288
8389 for child in marko_document.children:
84 # print(child)
8590 if isinstance(child, (Heading, SetextHeading)):
8691 title_text = obtain_heading_text(child)
8792 if child.level == 1:
359359 "properties": {
360360 "url": "https://mathoverflow.net/questions/20882/most-unintuitive-application-of-the-axiom-of-choice"
361361 },
362 "title": "lo.logic - Most 'unintuitive' "
363 "application of the Axiom of Choice? - "
364 "MathOverflow",
362 "title": r"lo.logic - Most \'unintuitive\' application of the Axiom of Choice? - MathOverflow",
365363 },
366364 {
367365 "anchor": "set-theory-set-theories-without-junk-theorems-mathoverflow",
370368 "properties": {
371369 "url": "http://mathoverflow.net/questions/90820/set-theories-without-junk-theorems/90945#90945"
372370 },
373 "title": "set theory - Set theories without "
374 '"junk" theorems? - MathOverflow',
371 "title": r"set theory - Set theories without \"junk\" theorems? - MathOverflow",
375372 },
376373 {
377 "anchor": "the-origin-of-the-number-zero",
374 "anchor": "the-origin-of-the-number-zero-history-smithsonian",
378375 "body": "\n",
379376 "images": [],
380377 "properties": {
381378 "url": "https://www.smithsonianmag.com/history/origin-number-zero-180953392/"
382379 },
383 "title": "The Origin of the Number Zero | History | Smithsonian",
380 "title": r"The Origin of the Number Zero \| History \| Smithsonian",
384381 },
385382 {
386 "anchor": "zajo-appler-apple",
383 "anchor": "zajo-appler-apple-emulator-for-ms-dos-written-in-8088-assembly",
387384 "body": "\n",
388385 "images": [],
389386 "properties": {"url": "https://github.com/zajo/appler"},
390 "title": "zajo/appler: Apple ][ emulator for MS-DOS, written in 8088 assembly",
387 "title": r"zajo/appler: Apple \]\[ emulator for MS-DOS, written in 8088 assembly",
391388 },
392389 {
393 "anchor": "computational",
390 "anchor": "computational-complexitytheory",
394391 "body": "\nThat is not a link.",
395392 "images": [],
396393 "properties": {},
397 "title": "Computational [Complexity](Theory)",
394 "title": r"Computational \[Complexity\]\(Theory\)",
398395 },
399396 ],
400397 "title": "Some Resources",