diff --git a/README.md b/README.md index e84ab6f..e1b7494 100644 --- a/README.md +++ b/README.md @@ -390,6 +390,13 @@ Here are some features we're planning to add in the future: ## Changelog +### v0.9.1 +- Delete print statement in `rich_text.py` + +### v0.9.0 +- pass the `pandoc_options` setting to wherever `pandoc.write` is called for consistency. Also, + this should reasonably be the expected behavior. + ### v0.8.2 - stop filtering linebreaks from table cells diff --git a/n2y/export.py b/n2y/export.py index bd73ca4..2d362eb 100644 --- a/n2y/export.py +++ b/n2y/export.py @@ -18,6 +18,7 @@ def _page_properties( page, pandoc_format=None, + pandoc_options=None, id_property=None, url_property=None, property_map=None, @@ -26,7 +27,7 @@ def _page_properties( pandoc_format = "markdown" if property_map is None: property_map = {} - properties = page.properties_to_values(pandoc_format) + properties = page.properties_to_values(pandoc_format, pandoc_options) if id_property in properties: logger.warning( 'The id property "%s" is shadowing an existing property with the same name', @@ -77,6 +78,7 @@ def export_page( page_properties = _page_properties( page, pandoc_format, + pandoc_options, id_property, url_property, property_map, @@ -123,16 +125,14 @@ def database_to_yaml( ): if content_property in database.schema: logger.warning( - ( - 'The content property "%s" is shadowing an existing ' - "property with the same name" - ), + 'The content property "%s" is shadowing an existing ' + "property with the same name", content_property, ) results = [] for page in database.children_filtered(notion_filter, notion_sorts): result = _page_properties( - page, pandoc_format, id_property, url_property, property_map + page, pandoc_format, pandoc_options, id_property, url_property, property_map ) if content_property: pandoc_ast = page.to_pandoc() diff --git a/n2y/page.py b/n2y/page.py index ad93a00..8ec4395 100644 --- a/n2y/page.py +++ b/n2y/page.py @@ -117,5 +117,8 @@ def to_pandoc(self, ignore_toc=False): ast = self.block.to_pandoc() return ast if ignore_toc else self.generate_toc(ast) - def properties_to_values(self, pandoc_format=None): - return {k: v.to_value(pandoc_format) for k, v in self.properties.items()} + def properties_to_values(self, pandoc_format=None, pandoc_options=None): + return { + k: v.to_value(pandoc_format, pandoc_options) + for k, v in self.properties.items() + } diff --git a/n2y/plugins/downloadfileproperty.py b/n2y/plugins/downloadfileproperty.py index bc66e0d..e4d4619 100644 --- a/n2y/plugins/downloadfileproperty.py +++ b/n2y/plugins/downloadfileproperty.py @@ -2,13 +2,12 @@ from os import makedirs, path from urllib.parse import urlparse - from n2y.property_values import FilesPropertyValue from n2y.utils import slugify class DownloadFilePropertyValue(FilesPropertyValue): - def to_value(self, _): + def to_value(self, _, __): url_list = [] for file in self.files: file_content = self.client._get_url(file.url, stream=True) diff --git a/n2y/property_values.py b/n2y/property_values.py index ff27599..7cbaa14 100644 --- a/n2y/property_values.py +++ b/n2y/property_values.py @@ -13,7 +13,7 @@ def __init__(self, client, notion_data, page): self.notion_type = notion_data["type"] self.page = page - def to_value(self, pandoc_format=None): + def to_value(self, pandoc_format=None, pandoc_options=None): raise NotImplementedError() @@ -24,7 +24,7 @@ def __init__(self, client, notion_data, page): super().__init__(client, notion_data, page) self.rich_text = client.wrap_notion_rich_text_array(notion_data["title"]) - def to_value(self, _=None): + def to_value(self, _=None, __=None): # Notion allows styling of the title, however, in their UI they display # the title property without any styling. Thus, if you copy/paste styled # text into a title this styling can be hidden and can re-appear after @@ -40,11 +40,11 @@ def __init__(self, client, notion_data, page): super().__init__(client, notion_data, page) self.rich_text = client.wrap_notion_rich_text_array(notion_data["rich_text"]) - def to_value(self, pandoc_format="gfm"): + def to_value(self, pandoc_format="gfm", pandoc_options=None): if pandoc_format is None: return self.rich_text.to_plain_text() else: - return self.rich_text.to_value(pandoc_format) + return self.rich_text.to_value(pandoc_format, pandoc_options) class NumberPropertyValue(PropertyValue): @@ -52,7 +52,7 @@ def __init__(self, client, notion_data, page): super().__init__(client, notion_data, page) self.number = notion_data["number"] - def to_value(self, _=None): + def to_value(self, _=None, __=None): return self.number @@ -61,7 +61,7 @@ def __init__(self, client, notion_data, page): super().__init__(client, notion_data, page) self.status = notion_data["status"] - def to_value(self, _=None): + def to_value(self, _=None, __=None): # Note: the Notion UI shouldn't allow you to have two statuses with the # same name nor should it allow no status at all return self.status @@ -80,7 +80,7 @@ def __init__(self, client, notion_data, page): self.name = None self.color = None - def to_value(self, _=None): + def to_value(self, _=None, __=None): # Note: the Notion UI shouldn't allow you to have two options with the # same name return self.name @@ -93,7 +93,7 @@ def __init__(self, client, notion_data, page): MultiSelectOption(self.client, no) for no in notion_data["multi_select"] ] - def to_value(self, _=None): + def to_value(self, _=None, __=None): # Note: the Notion UI shouldn't allow you to have two options with the # same name return [o.name for o in self.options] @@ -113,7 +113,7 @@ def __init__(self, client, notion_data, page): super().__init__(client, notion_data, page) self.value = process_notion_date(notion_data["date"]) - def to_value(self, _=None): + def to_value(self, _=None, __=None): return self.value def to_plain_text(self): @@ -125,7 +125,7 @@ def __init__(self, client, notion_data, page): super().__init__(client, notion_data, page) self.people = [client.wrap_notion_user(nu) for nu in notion_data["people"]] - def to_value(self, _=None): + def to_value(self, _=None, __=None): return [u.to_value() for u in self.people] @@ -134,7 +134,7 @@ def __init__(self, client, notion_data, page): super().__init__(client, notion_data, page) self.files = [client.wrap_notion_file(nf) for nf in notion_data["files"]] - def to_value(self, _): + def to_value(self, _, __): return [f.to_value() for f in self.files] @@ -143,7 +143,7 @@ def __init__(self, client, notion_data, page): super().__init__(client, notion_data, page) self.checkbox = notion_data["checkbox"] - def to_value(self, _): + def to_value(self, _, __): return self.checkbox @@ -152,7 +152,7 @@ def __init__(self, client, notion_data, page): super().__init__(client, notion_data, page) self.url = notion_data["url"] - def to_value(self, _=None): + def to_value(self, _=None, __=None): return self.url @@ -161,7 +161,7 @@ def __init__(self, client, notion_data, page): super().__init__(client, notion_data, page) self.email = notion_data["email"] - def to_value(self, _=None): + def to_value(self, _=None, __=None): return self.email @@ -170,7 +170,7 @@ def __init__(self, client, notion_data, page): super().__init__(client, notion_data, page) self.phone_number = notion_data["phone_number"] - def to_value(self, _=None): + def to_value(self, _=None, __=None): return self.phone_number @@ -184,7 +184,7 @@ def __init__(self, client, notion_data, page): else: self.value = notion_formula[notion_formula["type"]] - def to_value(self, _=None): + def to_value(self, _=None, __=None): return self.value @@ -200,7 +200,7 @@ def __init__(self, client, notion_data, page): for r in client._paginated_request(client._get_url, url, {}) ] - def to_value(self, _=None): + def to_value(self, _=None, __=None): return self.ids @@ -228,7 +228,7 @@ def __init__(self, client, notion_data, page): self.value = notion_rollup[notion_rollup["type"]] # TODO: handle arrays of dates - def to_value(self, pandoc_format="gfm"): + def to_value(self, pandoc_format="gfm", pandoc_options=None): if self.rollup_type == "date": return self.value elif self.rollup_type == "string": @@ -236,7 +236,7 @@ def to_value(self, pandoc_format="gfm"): elif self.rollup_type == "number": return self.value elif self.rollup_type == "array": - return [pv.to_value(pandoc_format) for pv in self.value] + return [pv.to_value(pandoc_format, pandoc_options) for pv in self.value] else: return self.value @@ -246,7 +246,7 @@ def __init__(self, client, notion_data, page): super().__init__(client, notion_data, page) self.created_time = fromisoformat(notion_data["created_time"]) - def to_value(self, _=None): + def to_value(self, _=None, __=None): return datetime.isoformat(self.created_time) @@ -255,7 +255,7 @@ def __init__(self, client, notion_data, page): super().__init__(client, notion_data, page) self.created_by = client.wrap_notion_user(notion_data["created_by"]) - def to_value(self, _=None): + def to_value(self, _=None, __=None): return self.created_by.to_value() @@ -264,7 +264,7 @@ def __init__(self, client, notion_data, page): super().__init__(client, notion_data, page) self.last_edited_time = fromisoformat(notion_data["last_edited_time"]) - def to_value(self, _=None): + def to_value(self, _=None, __=None): return datetime.isoformat(self.last_edited_time) @@ -273,7 +273,7 @@ def __init__(self, client, notion_data, page): super().__init__(client, notion_data, page) self.last_edited_by = client.wrap_notion_user(notion_data["last_edited_by"]) - def to_value(self, _=None): + def to_value(self, _=None, __=None): return self.last_edited_by.to_value() diff --git a/n2y/rich_text.py b/n2y/rich_text.py index 253c856..75ae384 100644 --- a/n2y/rich_text.py +++ b/n2y/rich_text.py @@ -2,17 +2,17 @@ from collections import deque from pandoc.types import ( - Str, - Space, - LineBreak, - Strong, - Emph, - Strikeout, Code, + Emph, + InlineMath, + LineBreak, Link, - Underline, Math, - InlineMath, + Space, + Str, + Strikeout, + Strong, + Underline, ) from n2y.logger import logger @@ -49,11 +49,11 @@ def __init__(self, client, notion_data, block=None): def to_pandoc(self): raise NotImplementedError() - def to_value(self, pandoc_format): + def to_value(self, pandoc_format, pandoc_options): return pandoc_write_or_log_errors( self.to_pandoc(), format=pandoc_format, - options=[], + options=pandoc_options, ) @classmethod @@ -211,11 +211,11 @@ def __getitem__(self, index): def to_pandoc(self): return sum([item.to_pandoc() for item in self.items], []) - def to_value(self, pandoc_format): + def to_value(self, pandoc_format, pandoc_options): return pandoc_write_or_log_errors( self.to_pandoc(), format=pandoc_format, - options=[], + options=pandoc_options, ) def to_plain_text(self): diff --git a/setup.py b/setup.py index 6fa335f..9b8243f 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name="n2y", - version="0.8.2", + version="0.9.1", description=description, long_description=description, long_description_content_type="text/x-rst", diff --git a/tests/test_property_values.py b/tests/test_property_values.py index 39544d8..aa36152 100644 --- a/tests/test_property_values.py +++ b/tests/test_property_values.py @@ -25,7 +25,7 @@ def process_property_value(notion_data, wrap_notion_user): else: wrap_notion_user.return_value = User(client, mock_user()) property_value = client.wrap_notion_property_value(notion_data, None) - return property_value.to_value("gfm") + return property_value.to_value("gfm", []) def test_title(): diff --git a/tests/test_rich_text.py b/tests/test_rich_text.py index 10a60cd..03dc3da 100644 --- a/tests/test_rich_text.py +++ b/tests/test_rich_text.py @@ -1,25 +1,25 @@ from pandoc.types import ( - Str, - Space, - Strong, - Emph, - Strikeout, Code, + Emph, + InlineMath, Link, Math, - InlineMath, + Space, + Str, + Strikeout, + Strong, Underline, ) -from n2y.notion import Client -from n2y.rich_text import RichTextArray, MentionRichText from n2y.mentions import PageMention +from n2y.notion import Client from n2y.notion_mocks import ( - mock_rich_text_array, mock_annotations, - mock_rich_text, mock_id, + mock_rich_text, + mock_rich_text_array, ) +from n2y.rich_text import MentionRichText, RichTextArray word = "word." spaced_word = " word." @@ -30,7 +30,7 @@ def process_rich_text_array(notion_data): client = Client("") rich_text_array = client.wrap_notion_rich_text_array(notion_data) pandoc_ast = rich_text_array.to_pandoc() - markdown = rich_text_array.to_value("markdown") + markdown = rich_text_array.to_value("markdown", []) plain_text = rich_text_array.to_plain_text() return pandoc_ast, markdown, plain_text @@ -124,9 +124,7 @@ def test_bold_space(): def test_italic_spaces(): - notion_data = mock_rich_text_array( - [("An", []), (" italic ", ["italic"]), (word, [])] - ) + notion_data = mock_rich_text_array([("An", []), (" italic ", ["italic"]), (word, [])]) pandoc_ast, markdown, plain_text = process_rich_text_array(notion_data) assert pandoc_ast == [Str("An"), Space(), Emph([Str("italic")]), Space(), Str(word)] assert markdown == "An *italic* word.\n" @@ -190,7 +188,8 @@ def test_blended_annotated_spaces(): Str("?"), ] assert ( - markdown == "**this** ***is*** *a*\n~~test~~[**` did`*" + markdown + == "**this** ***is*** *a*\n~~test~~[**` did`*" "*]{.underline}[` i pass`]{.underline}?\n" ) @@ -237,7 +236,8 @@ def test_equation_inline(): Str("indeed"), ] assert ( - markdown == "The Schrödinger Equation\n(${\\displaystyle " + markdown + == "The Schrödinger Equation\n(${\\displaystyle " "i\\hbar {\\frac {d}{dt}}\\vert \\Psi (t)\\" "rangle={\\hat {H}}\\vert \\Psi (t)\\rangle}$)\nis" " a very useful one indeed\n"