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

Assign ID to headers with CustomHTMLRenderer #84

Merged
merged 3 commits into from
Jul 2, 2023
Merged

Assign ID to headers with CustomHTMLRenderer #84

merged 3 commits into from
Jul 2, 2023

Conversation

pbogre
Copy link
Contributor

@pbogre pbogre commented Jun 30, 2023

I used ToastUI's customHTMLRenderer to assign an id attribute to all headers equal to the sanitized version of the text of that header.

a simplified version of this can be found in the customHTMLRenderer docs linked above, but my version is a little more extensive in the way it sanitizes the text as it removes all non-alphanumerical characters. Here are some examples of the sanitization:

  • "$$!!£!HeADinG \\1! !" -> "heading-1"
  • "Slightly more 'normal' heading 2" -> "slightly-more-normal-heading-2"
  • you can test this yourself with this jsfiddle

the sanitized text is then set as the header's id attribute, which allows for linking in markdown, and therefore tables of content and header tagging (#34). This is very similar, in fact practically the exact same, as how it is done in github, as shown below:

[link to section 1](#section-1) links to header with text that sanitizes to "section-1"
so for instance # Section 1 or ### SECTION 1!

The use of customHTMLRenderer is a really powerful addition, as it allows to add any parameters that you want to add in the future, like latex support (#61)

I tested this on my homeserver which runs in docker and everything ran smoothly and as expected. Perhaps some more testing could be done to see if the sanitizer works as intended for all titles, but because flatnotes is selfhosted this doesnt create any security flaw and as it stands now this solution works for everyday users as most people dont need fancy symbols in their headers.

@dullage
Copy link
Owner

dullage commented Jun 30, 2023

Hey @pbogre, this looks great! As soon as I get a chance I'll have a look and try and get it merged in. It would be a great addition.

@pbogre
Copy link
Contributor Author

pbogre commented Jun 30, 2023

was just testing this now and reinstalled the image, but i got a console error saying that customHTMLRenderer wasn't defined correctly. Silly me. the latest commit fixes that and has also been tested by declaring customHTMLRenderer inside the data function.

Copy link
Owner

@dullage dullage left a comment

Choose a reason for hiding this comment

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

I had a play around with this change today and it looks good. Just a couple of minor change requests then I can get it merged in.

flatnotes/src/components/NoteViewerEditor.vue Outdated Show resolved Hide resolved
flatnotes/src/components/NoteViewerEditor.vue Show resolved Hide resolved
flatnotes/src/components/NoteViewerEditor.vue Outdated Show resolved Hide resolved
@dullage dullage merged commit 82f20fe into dullage:develop Jul 2, 2023
Gedulis12 pushed a commit to Gedulis12/flatnotes that referenced this pull request Aug 7, 2023
Gedulis12 added a commit to Gedulis12/flatnotes that referenced this pull request Aug 7, 2023
Gedulis12 added a commit to Gedulis12/flatnotes that referenced this pull request Aug 7, 2023
Gedulis12 added a commit to Gedulis12/flatnotes that referenced this pull request Aug 7, 2023
* Revert "3.2.2"

This reverts commit 6b601fe.

* Revert "Corrected group variable typo in entrypoint.sh"

This reverts commit 3cb86a1.

* Revert "Updated README to resolve dullage#100"

This reverts commit 05fc652.

* Revert "3.2.1"

This reverts commit 4651830.

* Revert "Prevent recently modified from showing in read_only mode"

This reverts commit a3aa2a8.

* Revert "Various config settings are no longer required in read_only mode"

This reverts commit 3535978.

* Revert "3.2.0"

This reverts commit ee328bc.

* Revert "Updated README"

This reverts commit 253155a.

* Revert "Updated README"

This reverts commit b731a1c.

* Revert "Implement read-only mode"

This reverts commit 608a414.

* Revert "Fix theme issues. Resolves dullage#94."

This reverts commit 20725e8.

* Revert "Added _edit_only auth types"

This reverts commit 0e2a3f5.

* Revert "Remove async from path functions"

This reverts commit 161978c.

* Revert "3.1.1"

This reverts commit 8881755.

* Revert "Fix issue clicking links in unordered lists"

This reverts commit c3a073d.

* Revert "Disable checkboxes in view mode. Resolves dullage#81."

This reverts commit 1548b66.

* Revert "Formatting changes only"

This reverts commit 3aeb903.

* Revert "Assign ID to headers with CustomHTMLRenderer (dullage#84)"

This reverts commit 26e6b56.

* Revert "Ensure root knows when note title changes. Fixes dullage#82."

This reverts commit 851c640.

* Revert "Override default font-family for code blocks to fix dullage#78"

This reverts commit f9af501.

* Revert "Added VOLUME and EXPOSE keywords to Dockerfile"

This reverts commit 44e2b7a.

* Revert "3.1.0"

This reverts commit 8aa641c.

* Revert "Enabled extended autolinks"

This reverts commit 4b477f6.

* Revert "Ignore markdown codeblocks for tags (dullage#66)"

This reverts commit f7d206c.

* Revert "Fix get_tags method"

This reverts commit 99c2909.

* Revert "Updated README"

This reverts commit 39d54fc.

* Revert "3.0.3"

This reverts commit 5acf117.

* Revert "Secret key is now printed to console if using TOTP allowing for manual entry"

This reverts commit 5b74804.

* Revert "3.0.2"

This reverts commit 15d93af.

* Revert "Table headers in WYSIWYG editor now honour theme color"

This reverts commit 050b6d8.

* Revert "PR comments"

This reverts commit efdf4bf.

* Revert "Update site.webmanifest"

This reverts commit 285ab5d.
Gedulis12 pushed a commit to Gedulis12/flatnotes that referenced this pull request Aug 7, 2023
Gedulis12 pushed a commit to Gedulis12/flatnotes that referenced this pull request Aug 7, 2023
3.2.2

Revert "Corrected group variable typo in entrypoint.sh"

This reverts commit 3cb86a1.

Revert "Updated README to resolve dullage#100"

This reverts commit 05fc652.

Revert "3.2.1"

This reverts commit 4651830.

Revert "Prevent recently modified from showing in read_only mode"

This reverts commit a3aa2a8.

Revert "Various config settings are no longer required in read_only mode"

This reverts commit 3535978.

Revert "3.2.0"

This reverts commit ee328bc.

Revert "Updated README"

This reverts commit 253155a.

Revert "Updated README"

This reverts commit b731a1c.

Revert "Implement read-only mode"

This reverts commit 608a414.

Revert "Fix theme issues. Resolves dullage#94."

This reverts commit 20725e8.

Revert "Added _edit_only auth types"

This reverts commit 0e2a3f5.

Revert "Remove async from path functions"

This reverts commit 161978c.

Revert "3.1.1"

This reverts commit 8881755.

Revert "Fix issue clicking links in unordered lists"

This reverts commit c3a073d.

Revert "Disable checkboxes in view mode. Resolves dullage#81."

This reverts commit 1548b66.

Revert "Formatting changes only"

This reverts commit 3aeb903.

Revert "Assign ID to headers with CustomHTMLRenderer (dullage#84)"

This reverts commit 26e6b56.

Revert "Ensure root knows when note title changes. Fixes dullage#82."

This reverts commit 851c640.

Revert "Override default font-family for code blocks to fix dullage#78"

This reverts commit f9af501.

Revert "Added VOLUME and EXPOSE keywords to Dockerfile"

This reverts commit 44e2b7a.

Revert "3.1.0"

This reverts commit 8aa641c.

Revert "Enabled extended autolinks"

This reverts commit 4b477f6.

Revert "Ignore markdown codeblocks for tags (dullage#66)"

This reverts commit f7d206c.

Revert "Fix get_tags method"

This reverts commit 99c2909.

Revert "Updated README"

This reverts commit 39d54fc.

Revert "3.0.3"

This reverts commit 5acf117.

Revert "Secret key is now printed to console if using TOTP allowing for manual entry"

This reverts commit 5b74804.

Revert "3.0.2"

This reverts commit 15d93af.

Revert "Table headers in WYSIWYG editor now honour theme color"

This reverts commit 050b6d8.

Revert "PR comments"

This reverts commit efdf4bf.

Revert "Update site.webmanifest"

This reverts commit 285ab5d.

Update site.webmanifest

PR comments

Table headers in WYSIWYG editor now honour theme color

3.0.2

Secret key is now printed to console if using TOTP allowing for manual entry

3.0.3

Updated README

Fix get_tags method

Ignore markdown codeblocks for tags (dullage#66)

* Ignore markdown codeblocks for tags

* Changed `content_ex_tags` to use `content` instead of `content_ex_codeblock`

* Bumped `INDEX_SCHEMA_VERSION`

Enabled extended autolinks

3.1.0

Added VOLUME and EXPOSE keywords to Dockerfile

Override default font-family for code blocks to fix dullage#78

Ensure root knows when note title changes. Fixes dullage#82.

Assign ID to headers with CustomHTMLRenderer (dullage#84)

Formatting changes only

Disable checkboxes in view mode. Resolves dullage#81.

Fix issue clicking links in unordered lists

3.1.1

Remove async from path functions

Added _edit_only auth types

Fix theme issues. Resolves dullage#94.

Implement read-only mode

Updated README

Updated README

3.2.0

Various config settings are no longer required in read_only mode

Prevent recently modified from showing in read_only mode

3.2.1

Updated README to resolve dullage#100

Corrected group variable typo in entrypoint.sh

3.2.2

Revert "Master" (#3)

* Revert "3.2.2"

This reverts commit 6b601fe.

* Revert "Corrected group variable typo in entrypoint.sh"

This reverts commit 3cb86a1.

* Revert "Updated README to resolve dullage#100"

This reverts commit 05fc652.

* Revert "3.2.1"

This reverts commit 4651830.

* Revert "Prevent recently modified from showing in read_only mode"

This reverts commit a3aa2a8.

* Revert "Various config settings are no longer required in read_only mode"

This reverts commit 3535978.

* Revert "3.2.0"

This reverts commit ee328bc.

* Revert "Updated README"

This reverts commit 253155a.

* Revert "Updated README"

This reverts commit b731a1c.

* Revert "Implement read-only mode"

This reverts commit 608a414.

* Revert "Fix theme issues. Resolves dullage#94."

This reverts commit 20725e8.

* Revert "Added _edit_only auth types"

This reverts commit 0e2a3f5.

* Revert "Remove async from path functions"

This reverts commit 161978c.

* Revert "3.1.1"

This reverts commit 8881755.

* Revert "Fix issue clicking links in unordered lists"

This reverts commit c3a073d.

* Revert "Disable checkboxes in view mode. Resolves dullage#81."

This reverts commit 1548b66.

* Revert "Formatting changes only"

This reverts commit 3aeb903.

* Revert "Assign ID to headers with CustomHTMLRenderer (dullage#84)"

This reverts commit 26e6b56.

* Revert "Ensure root knows when note title changes. Fixes dullage#82."

This reverts commit 851c640.

* Revert "Override default font-family for code blocks to fix dullage#78"

This reverts commit f9af501.

* Revert "Added VOLUME and EXPOSE keywords to Dockerfile"

This reverts commit 44e2b7a.

* Revert "3.1.0"

This reverts commit 8aa641c.

* Revert "Enabled extended autolinks"

This reverts commit 4b477f6.

* Revert "Ignore markdown codeblocks for tags (dullage#66)"

This reverts commit f7d206c.

* Revert "Fix get_tags method"

This reverts commit 99c2909.

* Revert "Updated README"

This reverts commit 39d54fc.

* Revert "3.0.3"

This reverts commit 5acf117.

* Revert "Secret key is now printed to console if using TOTP allowing for manual entry"

This reverts commit 5b74804.

* Revert "3.0.2"

This reverts commit 15d93af.

* Revert "Table headers in WYSIWYG editor now honour theme color"

This reverts commit 050b6d8.

* Revert "PR comments"

This reverts commit efdf4bf.

* Revert "Update site.webmanifest"

This reverts commit 285ab5d.

Revert "Revert "Master" (#3)"

This reverts commit 44e3fc4.
Gedulis12 added a commit to Gedulis12/flatnotes that referenced this pull request Aug 7, 2023
* Update site.webmanifest

* PR comments

* Table headers in WYSIWYG editor now honour theme color

* 3.0.2

* Secret key is now printed to console if using TOTP allowing for manual entry

* 3.0.3

* Updated README

* Fix get_tags method

* Ignore markdown codeblocks for tags (dullage#66)

* Ignore markdown codeblocks for tags

* Changed `content_ex_tags` to use `content` instead of `content_ex_codeblock`

* Bumped `INDEX_SCHEMA_VERSION`

* Enabled extended autolinks

* 3.1.0

* Added VOLUME and EXPOSE keywords to Dockerfile

* Override default font-family for code blocks to fix dullage#78

* Ensure root knows when note title changes. Fixes dullage#82.

* Assign ID to headers with CustomHTMLRenderer (dullage#84)

* Formatting changes only

* Disable checkboxes in view mode. Resolves dullage#81.

* Fix issue clicking links in unordered lists

* 3.1.1

* Remove async from path functions

* Added _edit_only auth types

* Fix theme issues. Resolves dullage#94.

* Implement read-only mode

* Updated README

* Updated README

* 3.2.0

* Various config settings are no longer required in read_only mode

* Prevent recently modified from showing in read_only mode

* 3.2.1

* Updated README to resolve dullage#100

* Corrected group variable typo in entrypoint.sh

* 3.2.2

---------

Co-authored-by: Abraham Elias <46859202+abe6@users.noreply.github.com>
Co-authored-by: Abraham Elias <abraham@manjaro>
Co-authored-by: Adam Dullage <adam@dullage.com>
Co-authored-by: Adam Dullage <adam.dullage@itris.co.uk>
Co-authored-by: elmodor <elmodor@users.noreply.github.com>
Co-authored-by: Pietro Bonaldo Gregori <45976792+pbogre@users.noreply.github.com>
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