DEV Community

Vishnu Das Puthukudi
Vishnu Das Puthukudi

Posted on

"Enhancing Text2page: Adding Markdown and Code Block Support" #LAB 3

This week for my LAB-3, I am mainly working on using git to manage multiple simultaneous changes in a single project, and use git merges.
I have created 2 issues

  • issue-10 : Adding Support for a Horizontal Rule in Markdown
  • issue-11 : Adding Support for Inline Blocks and Fenced Code Blocks (Markdown)

Issue-10: Adding Support for Horizontal Rules (Markdown):
Un the Text2page project helps in rendering Markdown rules. Users found it difficult to produce aesthetically attractive and well structured HTML from documents from their Markdown files due to this restriction.
The first step in solving the issue was to figure out the Markdown pattern for horizontal rules. Horizontal rules in Markdown are usually indicated by three hyphens, asterisks, or underscores, separated by spaces. As an illustration, ---, *, or ___.
In order to add support for horizontal rules, I had to improve the parsing procedure to recognize the Markdown pattern for them.
**Code Snippet:

Here is a simplified code snippet that demonstrates the implementation of horizontal rule support in Text2page:

def create_html_from_markdown(input_file, output_dir, stylesheet_url=None):
    # ... (existing code)

    # Convert Markdown to HTML
    content = file.read()
    content_with_hr = parse_horizontal_rules(content)  # Custom function to identify and replace horizontal rules
    html_content = markdown2.markdown(content_with_hr)

    # ... (rest of the code)
Enter fullscreen mode Exit fullscreen mode

Issue-11 : Adding Support for Inline Blocks and Fenced Code Blocks (Markdown)
The Text2page project did not previously enable displaying markdown code blocks that were fenced and rendered inline. This restriction made it difficult for the users to efficiently add code snippets to the HTML documents they have been created from Markdown files.
The following steps made up the implementation process:
The initial step was to determine the Markdown patterns that stand in for code snippets. Markdown normally uses single backticks (') for inline code and three backticks (''') for fenced code blocks, which may or may not be followed by the language identification.
Here is a simplified code snippet that demonstrates the implementation of inline blocks and fenced code blocks support in Text2page:

def create_html_from_markdown(input_file, output_dir, stylesheet_url=None):
    # ... (existing code)

    # Convert Markdown to HTML
    content = file.read()
    content_with_code_blocks = parse_code_blocks(content)  # Custom function to identify and render code blocks
    html_content = markdown2.markdown(content_with_code_blocks)

    # ... (rest of the code)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)