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

change property name transform method for html id #178

Conversation

YusukeSuzuki
Copy link
Contributor

In the current version, html_id is not generated correctly when non-ascii characters such as Japanese are used in property names. I have changed from escaping to encoding in order to generate unique IDs while targeting non-ascii characters.

{
  "名前": {
    "description": "顧客の名前",
    "type": "string"
  },
  "年齢": {
    "description": "顧客の年齢",
    "type": "integer"
  }
}

Yusuke Suzuki and others added 2 commits November 17, 2022 16:16
@dblanchette
Copy link
Collaborator

Hi @YusukeSuzuki! Thanks for your contribution.

The reason the ID is escaped is to preserve some sort of of readability when sending direct links to users. For example, sending a link to the root property named "person" would be http://example.com/schema.html#person. I think changing this to something like http://example.com/schema.html#706572736f6e is a downgrade.

However, there has been a probelm since the beginning where several strings that escapes to the same value will cause duplicate ids (example: person and person_ will both become person_)

What I did is to combine the "human readable" id with a hex (limited to 8 chars). This should avoid most collisions since the hex uses the "real" value. Collisions are still possible because I limit the number of chars for the value not to explose in length.

The link would then be http://example.com/schema.html#person-72736f6e

This change will break all existing direct links to elements unfortunately.

Any thoughts, objections?

@dblanchette
Copy link
Collaborator

I completely changed my mind. Turns out it is totally acceptable to use kanji and other special characters in HTML IDs with HTML 5 which all modern browser supports.

I changed the PR to use all characters in IDs except spaces and escape characters. I also added a flag to restore the old behavior.

@dblanchette dblanchette merged commit ece81a8 into coveooss:main Nov 30, 2022
@dblanchette
Copy link
Collaborator

Released in version 0.44: https://github.com/coveooss/json-schema-for-humans/releases/tag/v0.44

@YusukeSuzuki YusukeSuzuki deleted the change-property-name-transform-method-for-html-id branch December 2, 2022 08:58
@Metodterapi Metodterapi linked an issue Feb 26, 2023 that may be closed by this pull request
Closed
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.

an
2 participants