-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from brunoarine/feat/ignore-front-matter
feat: ignore front matter
- Loading branch information
Showing
9 changed files
with
227 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,7 +198,7 @@ | |
"*.nuspec", | ||
"*.nvmrc", | ||
"*.ops", | ||
"org", | ||
"*.org", | ||
"*.pas", | ||
"*.pasm", | ||
"*.patch", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import re | ||
|
||
class Markup: | ||
def __init__(self, extension: str): | ||
self.extension = extension | ||
self._MARKUP_EXTENSIONS = { | ||
".org": self._strip_org_frontmatter | ||
} | ||
|
||
def strip_frontmatter(self, text: str) -> str: | ||
if self.extension in self._MARKUP_EXTENSIONS.keys(): | ||
return self._MARKUP_EXTENSIONS[self.extension](text) | ||
else: | ||
return text | ||
|
||
def _strip_org_frontmatter(self, content: str) -> str: | ||
""" | ||
Remove front matter from a string representing an Org-mode file. | ||
This function removes all lines from `:PROPERTIES:` to `:END:` | ||
and any lines starting with `#+` from the given content string. | ||
Args: | ||
content (str): The content of an Org-mode file as a string. | ||
Returns: | ||
str: The content with the front matter removed. | ||
Example: | ||
>>> content = ''' | ||
... :PROPERTIES: | ||
... :ID: 123 | ||
... :END: | ||
... #+TITLE: Example | ||
... This is some text. | ||
... ** A heading | ||
... Some more text. | ||
... ''' | ||
>>> cleaned_content = remove_front_matter(content) | ||
>>> print(cleaned_content) | ||
This is some text. | ||
** A heading | ||
Some more text. | ||
""" | ||
# Remove :PROPERTIES: to :END: block | ||
content = re.sub(r':PROPERTIES:(.|\n)*?:END:', '', content) | ||
|
||
# Remove lines starting with #+ | ||
pattern = r'^\s*#\+[a-zA-Z0-9_]+.*?$' | ||
content = re.sub(pattern, '', content, flags=re.MULTILINE) | ||
|
||
return content.strip() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[pytest] | ||
testpaths = | ||
tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[project] | ||
name = "findlike" | ||
version = "1.3.1" | ||
version = "1.4.0" | ||
authors = [{ name = "Bruno Arine", email = "[email protected]" }] | ||
description = "findlike is a package to retrieve similar documents" | ||
readme = "README.md" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.