Compare commits

..

2 Commits

Author SHA1 Message Date
ae1aa7bf9c Merge branch 'develop' into fix/strip-title
All checks were successful
Testing / pytest (push) Successful in 19s
Testing / mypy (push) Successful in 26s
Testing / style-formatting (push) Successful in 18s
Testing / style-sorted-imports (push) Successful in 18s
Testing / stability-extra-test (push) Successful in 21s
2025-04-15 21:57:53 +00:00
Lyz
6710775882
fix: strip token_list_to_plaintext
Some checks failed
Testing / pytest (push) Failing after 4s
Testing / mypy (push) Failing after 4s
Testing / style-formatting (push) Failing after 4s
Testing / style-sorted-imports (push) Failing after 3s
Testing / stability-extra-test (push) Failing after 4s
otherwise when you do headline.title.get_text() you may have trailing
whitespaces
2025-01-25 14:22:23 +01:00
3 changed files with 10 additions and 16 deletions

View File

@ -7,12 +7,6 @@ A python library to parse, modify and save Org-mode files.
- Modify these data and write it back to disk. - Modify these data and write it back to disk.
- Keep the original structure intact (indentation, spaces, format, ...). - Keep the original structure intact (indentation, spaces, format, ...).
** Principles
- Avoid any dependency outside of Python's standard library.
- Don't do anything outside of the scope of parsing/re-serializing Org-mode files.
- *Modification of the original text if there's no change is considered a bug (see [[id:7363ba38-1662-4d3c-9e83-0999824975b7][Known issues]]).*
- Data structures should be exposed as it's read on Emacs's org-mode or when in doubt as raw as possible.
- Data in the objects should be modificable as a way to update the document itself. *Consider this a Object-oriented design.*
** Safety mechanism ** Safety mechanism
As this library is still in early development. Running it over files might As this library is still in early development. Running it over files might
produce unexpected changes on them. For this reason it's heavily recommended to produce unexpected changes on them. For this reason it's heavily recommended to
@ -27,9 +21,6 @@ Also, see [[id:76e77f7f-c9e0-4c83-ad2f-39a5a8894a83][Known issues:Structure modi
not properly stored and can trigger this safety mechanism on a false-positive. not properly stored and can trigger this safety mechanism on a false-positive.
* Known issues * Known issues
:PROPERTIES:
:ID: 7363ba38-1662-4d3c-9e83-0999824975b7
:END:
** Structure modifications ** Structure modifications
:PROPERTIES: :PROPERTIES:
:ID: 76e77f7f-c9e0-4c83-ad2f-39a5a8894a83 :ID: 76e77f7f-c9e0-4c83-ad2f-39a5a8894a83

View File

@ -417,7 +417,6 @@ class Headline:
and line.delimiter_type == DelimiterLineType.END_BLOCK and line.delimiter_type == DelimiterLineType.END_BLOCK
and line.type_data.subtype == current_node.header.type_data.subtype and line.type_data.subtype == current_node.header.type_data.subtype
): ):
start = current_node.header.linenum start = current_node.header.linenum
end = line.linenum end = line.linenum
@ -824,7 +823,6 @@ class Headline:
def set_property(self, name: str, value: str): def set_property(self, name: str, value: str):
for prop in self.properties: for prop in self.properties:
# A matching property is found, update it # A matching property is found, update it
if prop.key == name: if prop.key == name:
prop.value = value prop.value = value
@ -1024,7 +1022,6 @@ class Headline:
and result_first[0] == "structural" and result_first[0] == "structural"
and result_first[1].strip().upper() == ":RESULTS:" and result_first[1].strip().upper() == ":RESULTS:"
): ):
(end_line, _) = self.get_structural_end_after( (end_line, _) = self.get_structural_end_after(
kword.linenum + 1 kword.linenum + 1
) )
@ -1819,7 +1816,7 @@ def token_list_to_plaintext(tok_list) -> str:
else: else:
assert isinstance(chunk, MarkerToken) assert isinstance(chunk, MarkerToken)
return "".join(contents) return "".join(contents).strip()
def token_list_to_raw(tok_list): def token_list_to_raw(tok_list):
@ -2041,7 +2038,6 @@ def tokenize_contents(contents: str) -> List[TokenItems]:
and is_pre(last_char) and is_pre(last_char)
and ((i + 1 < len(contents)) and is_border(contents[i + 1])) and ((i + 1 < len(contents)) and is_border(contents[i + 1]))
): ):
is_valid_mark = False is_valid_mark = False
# Check that is closed later # Check that is closed later
text_in_line = True text_in_line = True
@ -2434,7 +2430,6 @@ class OrgDoc:
# Writing # Writing
def dump_headline(self, headline, recursive=True): def dump_headline(self, headline, recursive=True):
tags = "" tags = ""
if len(headline.shallow_tags) > 0: if len(headline.shallow_tags) > 0:
tags = ":" + ":".join(headline.shallow_tags) + ":" tags = ":" + ":".join(headline.shallow_tags) + ":"
@ -2448,7 +2443,14 @@ class OrgDoc:
if not (raw_title.endswith(" ") or raw_title.endswith("\t")) and tags: if not (raw_title.endswith(" ") or raw_title.endswith("\t")) and tags:
tags_padding = " " tags_padding = " "
yield "*" * headline.depth + headline.spacing + state + raw_title + tags_padding + tags yield (
"*" * headline.depth
+ headline.spacing
+ state
+ raw_title
+ tags_padding
+ tags
)
planning = headline.get_planning_line() planning = headline.get_planning_line()
if planning is not None: if planning is not None:

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
# No external requirements at this point