|
1 | | -# Markdown Worker Examples |
| 1 | +# Example Markdown File |
2 | 2 |
|
3 | | -The `MarkdownParser` class provides various methods to parse and manipulate Markdown files. Here's a detailed explanation of each function and its usage: |
| 3 | +## Introduction |
| 4 | +This is a simple markdown file used for testing the MarkdownParser class. |
4 | 5 |
|
5 | | -## Class: MarkdownParser |
| 6 | +## Features |
| 7 | +- Reads Markdown files |
| 8 | +- Extracts headers and paragraphs |
| 9 | +- Searches for specific headings |
| 10 | +- Converts Markdown to HTML |
| 11 | +- Fetches Markdown from URLs |
| 12 | +- Supports advanced formatting (blockquotes, horizontal rules, tables, and images) |
| 13 | +- Provides interactive CLI mode |
6 | 14 |
|
7 | | -### `__init__(self, filename=None)` |
| 15 | +## Code Example |
| 16 | +```python |
| 17 | +print("Hello, World!") |
| 18 | +``` |
8 | 19 |
|
9 | | -- Description: Constructor for the `MarkdownParser` class. |
10 | | -- Parameters: |
11 | | - - `filename` (optional): A string representing the filename of the Markdown file to read. |
12 | | -- Usage: |
| 20 | +## Blockquote Example |
| 21 | +> This is a blockquote example. |
13 | 22 |
|
14 | | - ```python |
15 | | - parser = MarkdownParser('example.md') |
16 | | - ``` |
| 23 | +## Horizontal Rule Example |
| 24 | +--- |
17 | 25 |
|
18 | | -### `read_markdown_file(self)` |
| 26 | +## Table Example |
| 27 | +| Header 1 | Header 2 | |
| 28 | +|----------|----------| |
| 29 | +| Data 1 | Data 2 | |
| 30 | +| Data 3 | Data 4 | |
19 | 31 |
|
20 | | -- Description: Reads the content of the Markdown file and stores it in the `markdown_text` attribute. |
21 | | -- Returns: The content of the Markdown file as a string. |
22 | | -- Usage: |
| 32 | +## Image Example |
| 33 | + |
23 | 34 |
|
24 | | - ```python |
25 | | - parser = MarkdownParser('example.md') |
26 | | - content = parser.read_markdown_file() |
27 | | - ``` |
| 35 | +## Link Example |
| 36 | +[Mantresh](https://www.mantreshkhurana.com) |
28 | 37 |
|
29 | | -### `extract_headers_and_paragraphs(self)` |
30 | | - |
31 | | -- Description: Extracts headers and paragraphs from the Markdown file. |
32 | | -- Returns: |
33 | | - - `headers`: A list of strings containing the header titles. |
34 | | - - `paragraphs`: A list of strings containing the content of paragraphs. |
35 | | - - `header_indices`: A list of integers representing the line numbers of the headers in the Markdown file. |
36 | | -- Usage: |
37 | | - |
38 | | - ```python |
39 | | - parser = MarkdownParser('example.md') |
40 | | - headers, paragraphs, header_indices = parser.extract_headers_and_paragraphs() |
41 | | - ``` |
42 | | - |
43 | | -### `search_heading(self, heading_to_search)` |
44 | | - |
45 | | -- Description: Searches for a specific header in the Markdown file and returns its content. |
46 | | -- Parameters: |
47 | | - - `heading_to_search`: A string representing the header title to search for. |
48 | | -- Returns: The content of the header as a string. |
49 | | -- Usage: |
50 | | - |
51 | | - ```python |
52 | | - parser = MarkdownParser('example.md') |
53 | | - heading_content = parser.search_heading('Introduction') |
54 | | - ``` |
55 | | - |
56 | | -### `read_complete_file(self)` |
57 | | - |
58 | | -- Description: Returns the complete content of the Markdown file. |
59 | | -- Returns: The content of the entire Markdown file as a string. |
60 | | -- Usage: |
61 | | - |
62 | | - ```python |
63 | | - parser = MarkdownParser('example.md') |
64 | | - complete_content = parser.read_complete_file() |
65 | | - ``` |
66 | | - |
67 | | -### `read_line(self, line_number)` |
68 | | - |
69 | | -- Description: Reads a specific line from the Markdown file. |
70 | | -- Parameters: |
71 | | - - `line_number`: An integer representing the line number to read (0-based index). |
72 | | -- Returns: The content of the specified line as a string. |
73 | | -- Usage: |
74 | | - |
75 | | - ```python |
76 | | - parser = MarkdownParser('example.md') |
77 | | - line_content = parser.read_line(5) |
78 | | - ``` |
79 | | - |
80 | | -### `read_word(self, line_number, word_number)` |
81 | | - |
82 | | -- Description: Reads a specific word from a given line in the Markdown file. |
83 | | -- Parameters: |
84 | | - - `line_number`: An integer representing the line number (0-based index) to read. |
85 | | - - `word_number`: An integer representing the word number (0-based index) to read. |
86 | | -- Returns: The specified word from the specified line as a string. |
87 | | -- Usage: |
88 | | - |
89 | | - ```python |
90 | | - parser = MarkdownParser('example.md') |
91 | | - word_content = parser.read_word(10, 3) |
92 | | - ``` |
93 | | - |
94 | | -### `read_character(self, line_number, word_number, character_number)` |
95 | | - |
96 | | -- Description: Reads a specific character from a given word in a given line in the Markdown file. |
97 | | -- Parameters: |
98 | | - - `line_number`: An integer representing the line number (0-based index) to read. |
99 | | - - `word_number`: An integer representing the word number (0-based index) to read. |
100 | | - - `character_number`: An integer representing the character number (0-based index) to read. |
101 | | -- Returns: The specified character from the specified word in the specified line as a string. |
102 | | -- Usage: |
103 | | - |
104 | | - ```python |
105 | | - parser = MarkdownParser('example.md') |
106 | | - character = parser.read_character(15, 2, 4) |
107 | | - ``` |
108 | | - |
109 | | -### `read_character_from_line(self, line_number, character_number)` |
110 | | - |
111 | | -- Description: Reads a specific character from a given line in the Markdown file. |
112 | | -- Parameters: |
113 | | - - `line_number`: An integer representing the line number (0-based index) to read. |
114 | | - - `character_number`: An integer representing the character number (0-based index) to read. |
115 | | -- Returns: The specified character from the specified line as a string. |
116 | | -- Usage: |
117 | | - |
118 | | - ```python |
119 | | - parser = MarkdownParser('example.md') |
120 | | - character = parser.read_character_from_line(20, 10) |
121 | | - ``` |
122 | | - |
123 | | -### `read_character_from_file(self, character_number)` |
124 | | - |
125 | | -- Description: Reads a specific character from the entire Markdown file. |
126 | | -- Parameters: |
127 | | - - `character_number`: An integer representing the character number (0-based index) to read. |
128 | | -- Returns: The specified character from the Markdown file as a string. |
129 | | -- Usage: |
130 | | - |
131 | | - ```python |
132 | | - parser = MarkdownParser('example.md') |
133 | | - character = parser.read_character_from_file(50) |
134 | | - ``` |
135 | | - |
136 | | -### `read_word_from_line(self, line_number, word_number)` |
137 | | - |
138 | | -- Description: Reads a specific word from a given line in the Markdown file. |
139 | | -- Parameters: |
140 | | - - `line_number`: An integer representing the line number (0-based index) to read. |
141 | | - - `word_number`: An integer representing the word number (0-based index) to read. |
142 | | -- Returns: The specified word from the specified line as a string. |
143 | | -- Usage: |
144 | | - |
145 | | - ```python |
146 | | - parser = MarkdownParser('example.md') |
147 | | - word_content = parser.read_word_from_line(25, 5) |
148 | | - ``` |
149 | | - |
150 | | -### `markdown_to_html(self, markdown_text, output_filename=None)` |
151 | | - |
152 | | -- Description: Converts Markdown text to HTML format. |
153 | | -- Parameters: |
154 | | - - `markdown_text`: A string representing the Markdown content to convert to HTML. |
155 | | - - `output_filename` (optional): A string representing the filename to save the HTML output. If not provided, the function will only return the HTML string. |
156 | | -- Returns: The Markdown content converted to HTML as a string. |
157 | | -- Usage: |
158 | | - |
159 | | - ```python |
160 | | - parser = MarkdownParser() |
161 | | - html_output = parser.markdown_to_html('# Heading 1\n\n**Bold Text**') |
162 | | - ``` |
163 | | - |
164 | | -Note: To use most of the functions that read from the Markdown file (e.g., `read_line`, `read_word`, etc.), make sure to initialize the `MarkdownParser` instance with a valid Markdown file using the `filename` parameter. Otherwise, the `markdown_text` will be an empty string. |
| 38 | +## Conclusion |
| 39 | +This file provides test content to validate the MarkdownParser functionalities, including new features. |
0 commit comments