Search code examples
yaml

I want to perform text formatting in YAML


I am working on oracle chat bot and need formatted output string For example

“This is a book”   

In the above string only the word ‘book’ should appear in bold


Solution

  • If you want something like that, you can only use YAML to store the text. The formatting, and the way to emphasis book is up to the program that interprets the data loaded from YAML.

    If all the occurences of book should be boldened you could use a YAML file looking like:

    bold:
    - book
    text: |
        This is a book
    

    with the proper interpretation of the root-level mapping.

    Alternatively you could apply formatting like ReST or markdown, to the loaded text In that case your YAML could even be a root level scalar:

    --- |
    This is a **book**
    

    I use multi-document formats like that combining ReST, code and output to generate package documentation and for rendering stackoverflow answers that include program output.