Bridgeconn / usfm-grammar

An elegant USFM parser.
https://usfmgrammar.vachanengine.org/
MIT License
36 stars 14 forks source link

Usj to usfm #224

Closed kavitharaju closed 10 months ago

kavitharaju commented 11 months ago

This PR

:warning: The failing test cases are due to one testsuite file which needs a fix (\b should be \p)

How-To round trip

from usfm_grammar import USFMParser, Filter
from usfm_grammar import USFMParser, USFMGenerator

my_parser = USFMParser(input_usfm_str)
usj_obj = my_parser.to_usj()

my_generator = USFMGenerator()
my_generator.usj_to_usfm(usj_obj)
print(my_generator.usfm_string)

⚠️ There will be differences between first USFM and the generated one in 1. Spaces and lines 2. Default attributes will be given their names 3. Closing markers may be newly added

How-To remove unwanted markers from USFM

from usfm_grammar import USFMParser, Filter, USFMGenerator

my_parser = USFMParser(input_usfm_str)
usj_obj = my_parser.to_usj(include_markers=Filter.BCV+Filter.TEXT)

my_generator = USFMGenerator()
my_generator.usj_to_usfm(usj_obj)
print(my_generator.usfm_string)
kavitharaju commented 10 months ago

Changed the API as per the suggestion. This is how it is now

from usfm_grammar import USFMParser, Filter

my_parser = USFMParser(input_usfm_str)
usj_obj = my_parser.to_usj()

my_parser2 = USFMParser(from_usj=usj_obj)
print(my_parser2.usfm)