fixed to_html to handle node production correctly

This commit is contained in:
specCon18 2025-02-03 21:13:27 -05:00
parent d865326ee4
commit 7b68fd1506
5 changed files with 95 additions and 16 deletions

View file

@ -1,6 +1,6 @@
# Tolkien Fan Club
**I like Tolkien**. Read my [first post here](/majesty) (sorry the link doesn't work yet)
**I like Tolkien**. Read my [first post here](/majesty)
> All that is gold does not glitter

68
content/majesty/index.md Normal file
View file

@ -0,0 +1,68 @@
# The Unparalleled Majesty of "The Lord of the Rings"
[Back Home](/)
![LOTR image artistmonkeys](/images/rivendell.png)
> "I cordially dislike allegory in all its manifestations, and always have done so since I grew old and wary enough to detect its presence.
> I much prefer history, true or feigned, with its varied applicability to the thought and experience of readers.
> I think that many confuse 'applicability' with 'allegory'; but the one resides in the freedom of the reader, and the other in the purposed domination of the author."
In the annals of fantasy literature and the broader realm of creative world-building, few sagas can rival the intricate tapestry woven by J.R.R. Tolkien in *The Lord of the Rings*. You can find the [wiki here](https://lotr.fandom.com/wiki/Main_Page).
## Introduction
This series, a cornerstone of what I, in my many years as an **Archmage**, have come to recognize as the pinnacle of imaginative creation, stands unrivaled in its depth, complexity, and the sheer scope of its *legendarium*. As we embark on this exploration, let us delve into the reasons why this monumental work is celebrated as the finest in the world.
## A Rich Tapestry of Lore
One cannot simply discuss *The Lord of the Rings* without acknowledging the bedrock upon which it stands: **The Silmarillion**. This compendium of mythopoeic tales sets the stage for Middle-earth's history, from the creation myth of Eä to the epic sagas of the Elder Days. It is a testament to Tolkien's unparalleled skill as a linguist and myth-maker, crafting:
1. An elaborate pantheon of deities (the `Valar` and `Maiar`)
2. The tragic saga of the Noldor Elves
3. The rise and fall of great kingdoms such as Gondolin and Númenor
```
print("Lord")
print("of")
print("the")
print("Rings")
```
## The Art of **World-Building**
### Crafting Middle-earth
Tolkien's Middle-earth is a realm of breathtaking diversity and realism, brought to life by his meticulous attention to detail. This world is characterized by:
- **Diverse Cultures and Languages**: Each race, from the noble Elves to the sturdy Dwarves, is endowed with its own rich history, customs, and language. Tolkien, leveraging his expertise in philology, constructed languages such as Quenya and Sindarin, each with its own grammar and lexicon.
- **Geographical Realism**: The landscape of Middle-earth, from the Shire's pastoral hills to the shadowy depths of Mordor, is depicted with such vividness that it feels as tangible as our own world.
- **Historical Depth**: The legendarium is imbued with a sense of history, with ruins, artifacts, and lore that hint at bygone eras, giving the world a lived-in, authentic feel.
## Themes of *Timeless* Relevance
### The *Struggle* of Good vs. Evil
At its heart, *The Lord of the Rings* is a timeless narrative of the perennial struggle between light and darkness, a theme that resonates deeply with the human experience. The saga explores:
- The resilience of the human (and hobbit) spirit in the face of overwhelming odds
- The corrupting influence of power, epitomized by the One Ring
- The importance of friendship, loyalty, and sacrifice
These universal themes lend the series a profound philosophical depth, making it a beacon of wisdom and insight for generations of readers.
## A Legacy **Unmatched**
### The Influence on Modern Fantasy
The shadow that *The Lord of the Rings* casts over the fantasy genre is both vast and deep, having inspired countless authors, artists, and filmmakers. Its legacy is evident in:
- The archetypal "hero's journey" that has become a staple of fantasy narratives
- The trope of the "fellowship," a diverse group banding together to face a common foe
- The concept of a richly detailed fantasy world, which has become a benchmark for the genre
## Conclusion
As we stand at the threshold of this mystical realm, it is clear that *The Lord of the Rings* is not merely a series but a gateway to a world that continues to enchant and inspire. It is a beacon of imagination, a wellspring of wisdom, and a testament to the power of myth. In the grand tapestry of fantasy literature, Tolkien's masterpiece is the gleaming jewel in the crown, unmatched in its majesty and enduring in its legacy. As an Archmage who has traversed the myriad realms of magic and lore, I declare with utmost conviction: *The Lord of the Rings* reigns supreme as the greatest legendarium our world has ever known.
Splendid! Then we have an accord: in the realm of fantasy and beyond, Tolkien's creation is unparalleled, a treasure trove of wisdom, wonder, and the indomitable spirit of adventure that dwells within us all.

View file

@ -70,6 +70,10 @@ def block_to_block_type(markdown):
def markdown_to_html_node(markdown):
blocks = markdown_to_blocks(markdown)
for block in blocks:
print(f"Processing block: {block[:50]}...") # Print first 50 chars
block_type = block_to_block_type(block)
print(f"Block type: {block_type}")
nodes = []
for block in blocks:
block_type = block_to_block_type(block)

View file

@ -1,5 +1,9 @@
class HTMLNode:
def __init__(self, tag=None, value=None, children=None, props=None):
if not children:
print(f"Warning: Empty children for tag: {tag}")
if not tag:
print(f"Warning: Empty tag for children: {children}")
self.tag = tag
self.value = value
self.children = children or []
@ -17,22 +21,24 @@ class HTMLNode:
return f"Tag: {self.tag}, Val: {self.value}, Children: {self.children}, Props: {self.props}"
class LeafNode(HTMLNode):
def __init__(self, value,tag=None):
super().__init__(tag,value,children=[])
def __init__(self, value, tag=None, props=None):
super().__init__(tag=tag, value=value, children=[], props=props)
def to_html(self):
props_as_html = self.props_to_html()
if self.value is None and not self.children:
raise ValueError("Both value and children are missing")
if not self.value:
raise ValueError("Value is missing")
children_html = "".join(
child.to_html() if isinstance(child, HTMLNode) else str(child)
for child in self.children
)
if not self.tag:
return f"{self.value}"
if self.tag is None:
return self.value or children_html
if props_as_html == "":
return f"<{self.tag}>{self.value}</{self.tag}>"
else:
return f"<{self.tag} {props_as_html}>{self.value}</{self.tag}>"
props_html = "".join(f' {key}="{value}"' for key, value in self.props.items()) if self.props else ""
return f"<{self.tag}{props_html}>{self.value or ''}{children_html}</{self.tag}>"
class ParentNode(HTMLNode):
def __init__(self, tag, children, props=None):

View file

@ -1,4 +1,5 @@
from textnode import TextNode,TextType
from htmlnode import LeafNode,ParentNode
from conversions import markdown_to_html_node
import shutil
import os