|
16 | 16 | parser.add_argument('--readme_path', help='Path to the tlaplus/examples README.md file', required=True)
|
17 | 17 | args = parser.parse_args()
|
18 | 18 |
|
19 |
| -readme = None |
20 |
| -with open(normpath(args.readme_path), 'r', encoding='utf-8') as readme_file: |
21 |
| - readme = mistletoe.Document(readme_file) |
22 |
| - |
23 | 19 | columns = ['name', 'authors', 'beginner', 'proof', 'tlc', 'pcal', 'apalache']
|
24 | 20 |
|
25 | 21 | def get_column(row, index):
|
@@ -64,11 +60,21 @@ def format_table(table):
|
64 | 60 | '''
|
65 | 61 | return
|
66 | 62 |
|
67 |
| -table = next((child for child in readme.children if isinstance(child, Table))) |
68 |
| -format_table(table) |
| 63 | +def format_document(document): |
| 64 | + ''' |
| 65 | + All document transformations should go here. |
| 66 | + ''' |
| 67 | + # Gets table of local specs |
| 68 | + table = next((child for child in document.children if isinstance(child, Table))) |
| 69 | + format_table(table) |
69 | 70 |
|
70 |
| -# Write formatted markdown to README.md |
71 |
| -with open(normpath(args.readme_path), 'w', encoding='utf-8') as readme_file: |
72 |
| - with MarkdownRenderer() as renderer: |
| 71 | +# Read, format, write |
| 72 | +# Need to both parse & render within same MarkdownRenderer context to preserve other formatting |
| 73 | +with MarkdownRenderer() as renderer: |
| 74 | + readme = None |
| 75 | + with open(normpath(args.readme_path), 'r', encoding='utf-8') as readme_file: |
| 76 | + readme = mistletoe.Document(readme_file) |
| 77 | + format_document(readme) |
| 78 | + with open(normpath(args.readme_path), 'w', encoding='utf-8') as readme_file: |
73 | 79 | readme_file.write(renderer.render(readme))
|
74 | 80 |
|
0 commit comments