Skip to content

Commit

Permalink
Add function for simple string transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
MaddyGuthridge committed Jan 24, 2025
1 parent c081d0a commit 073f337
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion transdoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,31 @@
"TransdocRule",
]

from io import StringIO
from .__rule import TransdocRule
from .__consts import VERSION as __version__
from .__transformer import TransdocTransformer
from .handlers import TransdocHandler
from .handlers import TransdocHandler, PlaintextHandler
from .__transform_tree import transform_tree
from .__transform_file import transform_file


def transform(
transformer: TransdocTransformer,
input: str,
path: str = "<string>",
) -> str:
"""
Transform the given input string.
Args:
transformer (TransdocTransformer): Transformer with all desired rules
input (str): input string to transform
path (str, optional): name of input string to use when reporting errors
"""
handlers = [PlaintextHandler()]
in_buf = StringIO(input)
out_buf = StringIO()
transform_file(handlers, transformer, path, in_buf, out_buf)
out_buf.seek(0)
return out_buf.read()

0 comments on commit 073f337

Please sign in to comment.