AsciiDoc links¶

Create list of AsciiDoc links from YAML

Structure of YAML file:

- name:
  note:
  history:
    - date:
      file:

Usage:

usage: adoc_links.py [-h] input_yaml output_adoc

Create AsciiDoc links from YAML.

positional arguments:
  input_yaml   Input YAML file
  output_adoc  Output AsciiDoc file

options:
  -h, --help   show this help message and exit

Parse arguments:

parser = argparse.ArgumentParser(description="Create AsciiDoc links from YAML.")

parser.add_argument("input_yaml", help="Input YAML file")

parser.add_argument("output_adoc", help="Output AsciiDoc file")

args = parser.parse_args()

Read YAML file:

with open(args.input_yaml, 'r') as file:
    data = yaml.safe_load(file)

def format_note(note):
    lines = note.strip().split("\n")
    note = " - ".join(lines)
    return note

Output YAML records as a table with n_cols columns.

n_cols = 3

Specify n_cols headers of 1 width.

def repeat_string_n_times(s, n):
    return ",".join(s for _ in range(n))

text = f"""
[cols="{repeat_string_n_times('1',n_cols)}"]
|===
"""

for d in data:
    icon = d['icon']
    link = d['link']
    name = d['name']
    note = d['note']
    note = format_note(note)

    text += textwrap.dedent(f"""
        a|
        ====
        icon:{icon}[2x,role={{c}}flag]  
        link:{link}[*{name}*] +
           
        """)
    text += f"_{note}_\n====\n"

Fill the remaining columns with blanks:

def calculate_empty_elements(len_data, n_col):
    # Calculate the number of elements in the last row
    elements_in_last_row = len_data % n_col

    # If the last row is completely filled, there are no empty elements
    if elements_in_last_row == 0:
        return 0

    # Return the number of empty elements in the last row
    return n_col - elements_in_last_row

for _ in range(calculate_empty_elements(len(data), n_cols)):
    text += f"a|\n"

Close the table:

text += """
|===
"""

Write output file:

with open(args.output_adoc, 'w') as file:
    file.write(text)

print(f"AsciiDoc links created: {args.output_adoc}")

lit

Navigation

Contents:

  • Note-OpenAI
  • Book Chat (LC)
  • Udemy
  • Udemy HTML TOC
  • Note-AI
  • Markdown Viewer
  • QR-Code
  • Obsidian Chat (LI)
  • Obsidian-AI
  • Obsidian Web Editor
  • Obsidian Bases
  • Grafana NPE
  • Grafana Record
  • Grafana Panels
  • Grafana Stats
  • Neo RAG
  • Book Chat (LI)
  • LlamaIndex Extractors
  • Llamaindex Router
  • Time Intervals
  • Pandoc UI
  • Jira Stats
  • Explain Java
  • Code Review
  • FB Prompts Edit
  • FB Prompts Xml
  • Doc-Note
  • Upload File
  • EPUB TOC
  • POM CSV
  • exc yaml
  • exc UI
  • exc histo
  • Log Chunk
  • curl clean
  • Сравнение папок
  • AsciiDoc links
  • Google Search
  • Ollama Chat
  • Compare Text
  • Compare Properties
  • Rasp Hotkeys
  • Bilingua
  • Create Image
  • Albums
  • GMail Clean
  • YouTube Transcript
  • FW Picture
  • Шашки
  • Persisted List

Related Topics

  • Documentation overview
    • Previous: Сравнение папок
    • Next: Google Search
©2026, EA. | Powered by PyLit 3.1.1 & Sphinx 8.2.3 & Alabaster 1.0.0 | Page source