Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add in-text work citations #50

Merged
merged 5 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 48 additions & 19 deletions heidegger_index/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ def convert_md(content):


RE_LEMMA_LINK = r"\[\[([^\]\n]+)\]\]" # e.g. [[Aristoteles]]
# For citations were adhering to Pandoc's syntax.
# See https://pandoc.org/chunkedhtml-demo/8.20-citation-syntax.html
RE_WORK_CIT = r"\[@([^\]\n]+?)\]" # e.g. [@GA-62, p. 4]
RE_IN_TEXT_WORK_CIT = r"(?<!\[)@(\w[^\s,{}]*\w+)|@{([^\n{}]+?)}" # e.g. @GA-29/30 and @{GA 29/30}


class LemmaLinkInlineProcessor(InlineProcessor):
Expand All @@ -38,38 +41,61 @@ def handleMatch(self, m, data):

el.text = display_value.strip()
return el, m.start(), m.end()

class WorkLinkInlineProcessor(InlineProcessor):
johannesdewit marked this conversation as resolved.
Show resolved Hide resolved
def build_element(self, work_key, locator, citation=True):
el = etree.Element("span")
if citation:
el.text = "(" # Opening citation
try:
work_obj = Work.objects.get(key=work_key)
except Work.DoesNotExist:
work_el = etree.SubElement(el, "span")
print(f"Markdown conversion: cited work {work_key} does not exist")
else:
href = reverse("work-detail", kwargs={"slug": work_obj.slug})
work_el = etree.SubElement(el, "a", href=href)
if citation:
work_el.text = work_key
else:
work_el.text = work_obj.title

if locator:
work_el.tail = f", {locator.strip()}" # Closing citation
if citation:
if work_el.tail:
work_el.tail += ")"
else:
work_el.tail = ")"

class WorkCitationInlineProcessor(InlineProcessor):
return el


class WorkCitationInlineProcessor(WorkLinkInlineProcessor):
def handleMatch(self, m, data):
citation = m.group(1)
if "," in citation:
work_key, citation = citation.split(",", maxsplit=1)
work_key, locator = citation.split(",", maxsplit=1)
else:
work_key = citation
citation = ""
locator = ""

work_key = work_key.strip()
citation = citation.strip()
locator = locator.strip()

el = etree.Element("span")
el.text = "(" # Opening citation
try:
work_obj = Work.objects.get(key=work_key)
except Work.DoesNotExist:
work_el = etree.SubElement(el, "span")
work_el.attrib["class"] = "italic"
print(f"Markdown conversion: cited work {work_key} does not exist")
else:
href = reverse("work-detail", kwargs={"slug": work_obj.slug})
work_el = etree.SubElement(el, "a", href=href)
el = self.build_element(work_key, locator, citation=True)

work_el.text = work_key
return el, m.start(), m.end()

if citation:
work_el.tail = f", {citation.strip()})" # Closing citation

class InTextWorkCitInlineProcessor(WorkLinkInlineProcessor):
def handleMatch(self, m, data):
if m.group(1):
work_key = m.group(1)
else:
work_el.tail = ")"
work_key = m.group(2)

el = self.build_element(work_key, locator="", citation=False)

return el, m.start(), m.end()

Expand Down Expand Up @@ -107,4 +133,7 @@ def extendMarkdown(self, md):
md.inlinePatterns.register(
WorkCitationInlineProcessor(RE_WORK_CIT, md), "work_cit", 41
)
md.inlinePatterns.register(
InTextWorkCitInlineProcessor(RE_IN_TEXT_WORK_CIT, md), "work_link", 42
)
md.parser.blockprocessors["quote"] = NonLazyBlockQuoteBlockProcessor(md.parser)
2 changes: 1 addition & 1 deletion index/descriptions/FT.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
_Die Frage nach der Technik_ is a small text that is found in several places. In the Gesamtausgabe it is part of [@VA]. It has also been published in the smaller edition [@TK]. Please be aware of this when using the index.
_Die Frage nach der Technik_ is a small text that is found in several places. In the Gesamtausgabe it is part of @VA. It has also been published in the smaller edition @TK. Please be aware of this when using the index.
2 changes: 1 addition & 1 deletion index/descriptions/GA 5.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Although most older publications refer to the page numbers of the original publication of *Holzwege*, all our references refer to pages of the *Gesamtausgabe band 5*, which also prints the original page numbers in the margin. This is also applied to the individual texts contained in the volume. (This means that [@UK], [@ZW] and [@WD] are all refered to by their pages within *GA 5*.)
Although most older publications refer to the page numbers of the original publication of *Holzwege*, all our references refer to pages of the *Gesamtausgabe band 5*, which also prints the original page numbers in the margin. This is also applied to the individual texts contained in the volume. (This means that @UK, @ZW and @WD are all refered to by their pages within *GA 5*.)
2 changes: 1 addition & 1 deletion index/descriptions/TK.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
_Die Technik und die Kehre_ is a small booklet containing two lectures which were given as part of the lecture course _Einblick in das was ist_. The two lectures contained are _Die Frage nach der Technik_ and _Die Kehre_.

_Die Frage nach der Technik_ is also contained in [@VA] and _Die Kehre_ is also part of [@EWI] and a chapter in [@GA 11]. Please be aware of this when using the index for these works.
_Die Frage nach der Technik_ is also contained in @VA and _Die Kehre_ is also part of @EWI and a chapter in @{GA 11}. Please be aware of this when using the index for these works.
4 changes: 2 additions & 2 deletions index/descriptions/VA.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Parts of _Vorträge und Aufsätze_ are also contained in other works:

- _Die Frage nach der Technik_ is also part of [@TK].
- _Das Ding_ is also part of [@EWI].
- _Die Frage nach der Technik_ is also part of @TK.
- _Das Ding_ is also part of @EWI.
Loading