Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some fixes #81

Merged
merged 9 commits into from
Feb 12, 2024
Merged

Some fixes #81

merged 9 commits into from
Feb 12, 2024

Conversation

sayanarijit
Copy link
Member

@sayanarijit sayanarijit commented Feb 9, 2024

  • html.escape the all attributes
  • Match link domain more precisely.
  • Image height or width can be individually specified

- urllib.quote_plus the url attributes
- Match link domain more precisely.
- Image height or width can be individually specified
@sayanarijit sayanarijit marked this pull request as ready for review February 9, 2024 07:24
@sayanarijit
Copy link
Member Author

Ref: #82

Copy link
Contributor

@rajatsingla rajatsingla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we can do formatting changes in a separate pr, like single quote to double quote and other things, that would make reviewing actual logic changes a bit easier.

@@ -1,6 +1,6 @@
{%- set language = node.attrs.language|default("") -%}
{%- if node.content -%}
{%- set text = escape(node.content[0].text) -%}
{%- set text node.content[0].text -%}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is = needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not idea. But it helps visually.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it is needed, without = it will fail

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I thought i added = will fix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

return store['json'], store['html']
store[data_type][file.split(f".{data_type}")[0]] = data

## Use this to (re)generate the html files
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a fan of commented code, please see if this is really needed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s handy when the change affects a lot of html files. We can move it to a script or separate function, but this comment is in tests, not in lib. So maybe we can keep it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seperate function sounds good

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an optional argument rebuilt_html=False, to avoid duplication.

@@ -39,22 +43,37 @@ def _get_abs_template_path(path_str):
return os.path.join(pkg_dir, path_str)


class BaseDoc:
def escape_recursive(node):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming suggestion-> escape_json

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor refactor suggestion:

def escape_json(data):
""" Escape strings, or recursively escape lists and dictionaries.
skip escape for dictionary keys listed in skip_keys
"""
skip_keys = ["html"]
...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On naming: it’s not escaping json. It’s taking dict (block/node) as input and recursively html escaping all the values.

on skip_keys, it’s currently only one attribute we need to skip. Not sure if there will ever be another key to skip. So making a separate list for it seems overkill for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah any name works, escape_recursive is also ok, in my mind escape_value or escape_json sounds better..

"html" in if condition is without any context and is confusing, if not list, can be assigned to a variable at the least.
and a comment can be added

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to escape_values_recursive. Also added skip_key = "html" # Skip escaping html values in embeds.

@rajatsingla
Copy link
Contributor

Thanks, LGTM

@sayanarijit sayanarijit merged commit 0c2c1e7 into master Feb 12, 2024
3 checks passed
@sayanarijit sayanarijit deleted the fixes branch February 12, 2024 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants