summaryrefslogtreecommitdiffstats
path: root/web_src/js/markup
Commit message (Collapse)AuthorAgeFilesLines
* Fix and rewrite markup anchor processing (#29931) (#29946)Giteabot2024-03-211-33/+51
| | | | | | | | Backport #29931 by @lunny Fix #29877 Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: silverwind <me@silverwind.io>
* Use more specific selector for `name` links (#29679) (#29681)Giteabot2024-03-091-1/+1
| | | | | | | | | | | | Backport #29679 by @silverwind Followup https://github.com/go-gitea/gitea/pull/29305. As per discussion in https://github.com/go-gitea/gitea/pull/29666#discussion_r1517506422, make this selector only search in the current `.markup` document, as there can be multiples displayed at the same time. @DanielMatiasCarvalho maybe you can review. Co-authored-by: silverwind <me@silverwind.io>
* Fix user-defined markup links targets (#29305) (#29666)Giteabot2024-03-081-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Backport #29305 by @DanielMatiasCarvalho This seeks to fix the bug reported on issue #29196. Cause: ID's with custom characters (- , _ , etc.), were not linking correctly in the Markdown file when rendered in the browser because the ID in the respective destinies would be different than the one in anchor, while for IDs with only letters, the ID would be the same. Fix: It was suggested that to fix this bug, it should more or less like GitHub does it. While in gitea the anchors would be put in HTML like this: ``` <p dir="auto"><a href="#user-content-_toc152597800" rel="nofollow">Review</a></p> <p dir="auto"><a href="#user-content-_toc152597802" rel="nofollow">Staging</a></p> <p dir="auto"><a href="#user-content-_toc152597803" rel="nofollow">Development</a></p> <p dir="auto"><a href="#user-content-_toc152597828" rel="nofollow">Testing</a></p> <p dir="auto"><a href="#user-content-_toc152597829" rel="nofollow">Unit-tests</a></p> ``` In GitHub, the same anchor's href properties would be the same without "user-content-" trailing behind. So my code made sure to change those anchors, so it would not include "user-content-" and then add respective Event Listeners so it would scroll into the supposed places. Fixes: #29196 Co-authored-by: DC <106393991+DanielMatiasCarvalho@users.noreply.github.com> Co-authored-by: silverwind <me@silverwind.io>
* Strip trailing newline in markdown code copy (#29019) (#29022)Giteabot2024-02-011-1/+3
| | | | | | | Behaviour now matches GH. Safeguard added in the for loop because `textContent` may be null in which case it does not make sense to render the copy button. Co-authored-by: silverwind <me@silverwind.io>
* Change katex limits (#27823) (#27868)Giteabot2023-11-011-2/+12
| | | | | | | | | | | | Backport #27823 by @KN4CK3R Fixes #27812 Use higher defaults again but limit the input size. ![grafik](https://github.com/go-gitea/gitea/assets/1666336/23cdf572-de30-4799-b9cf-ef386b1623b9) Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
* Fix mermaid flowchart margin issue (#27503) (#27516)silverwind2023-10-081-1/+3
| | | | | | | | | | Backport https://github.com/go-gitea/gitea/pull/27503 to 1.21 Fixes: https://github.com/go-gitea/gitea/issues/27435 Related: https://github.com/mermaid-js/mermaid/issues/4907 <img width="924" alt="image" src="https://github.com/go-gitea/gitea/assets/115237/494a1d2e-4c56-48d0-9843-82a5e5aa977e">
* Fix task list checkbox toggle to work with YAML front matter (#25184)Jonathan Tran2023-06-131-0/+8
| | | | | | | | Fixes #25160. `data-source-position` of checkboxes in a task list was incorrect whenever there was YAML front matter. This would result in issue content or PR descriptions getting corrupted with random `x` or space characters when a user checked or unchecked a task.
* Fix math and mermaid rendering bugs (#24049)silverwind2023-04-175-40/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1. Fix multiple error display for math and mermaid: ![err](https://user-images.githubusercontent.com/115237/231126411-8a21a777-cd53-4b7e-ac67-5332623106e8.gif) 2. Fix height calculation of certain mermaid diagrams by reading the iframe inner height from it's document instead of parsing it from SVG: Before: <img width="866" alt="Screenshot 2023-04-11 at 11 56 27" src="https://user-images.githubusercontent.com/115237/231126480-b194e02b-ea8c-4ddf-8c79-50c525815d92.png"> After: <img width="855" alt="Screenshot 2023-04-11 at 11 56 35" src="https://user-images.githubusercontent.com/115237/231126494-5fe86a48-8d21-455a-8b95-79b6ee27a16f.png"> 3. Refactor error handling to a common function 4. Rename to `renderAsciicast` for consistency 5. Improve mermaid loading sequence Note: I did try `securityLevel: 'sandbox'` to make mermaid output a iframe directly, but that showed a bug in mermaid where the iframe style height was set incorrectly. Opened https://github.com/mermaid-js/mermaid/issues/4289 for this. --------- Co-authored-by: Giteabot <teabot@gitea.io>
* update to mermaid v10 (#23178)techknowlogick2023-03-041-21/+20
| | | | | | | fix #23153 --------- Co-authored-by: silverwind <me@silverwind.io>
* Move helpers to be prefixed with `gt-` (#22879)zeripath2023-02-132-2/+2
| | | | | | | | | | | | | | | | | | | | As discussed in #22847 the helpers in helpers.less need to have a separate prefix as they are causing conflicts with fomantic styles This will allow us to have the `.gt-hidden { display:none !important; }` style that is needed to for the reverted PR. Of note in doing this I have noticed that there was already a conflict with at least one chroma style which this PR now avoids. I've also added in the `gt-hidden` style that matches the tailwind one and switched the code that needed it to use that. Signed-off-by: Andrew Thornton <art27@cantab.net> --------- Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Load asciicast css async (#22502)Jason Song2023-01-181-1/+4
| | | | | Load asciicast css asynchronously. Related to #22448.
* Support asciicast files as new markup (#22448)Jason Song2023-01-182-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Support [asciicast files](https://github.com/asciinema/asciinema/blob/develop/doc/asciicast-v2.md) as a new markup via [asciinema-player](https://github.com/asciinema/asciinema-player). For more on asciinema, see the [introduction](https://asciinema.org/). So users can use asciinema recorder to generate an asciicast file (or you can download a sample file from https://asciinema.org/a/335480.cast?dl=1), then upload it to Gitea and play it on Gitea. Snapshots: <details> ## Upload asciicast files <img width="1134" alt="image" src="https://user-images.githubusercontent.com/9418365/212461061-cc2c7181-0e14-4534-af55-1ec60a639fd1.png"> ## Open an asciicast file <img width="1137" alt="image" src="https://user-images.githubusercontent.com/9418365/212461090-a3b5141f-4894-430d-a2b4-ea257801a0ed.png"> ## Play it <img width="1144" alt="image" src="https://user-images.githubusercontent.com/9418365/212461157-4e82db69-0e41-471d-928f-ac1fe0737105.png"> ## Copy contents from the "video" <img width="1145" alt="image" src="https://user-images.githubusercontent.com/9418365/212461286-211612bc-15d6-427a-89a9-6abff5c6a0a5.png"> ## View the source <img width="1140" alt="image" src="https://user-images.githubusercontent.com/9418365/212461187-05473b2d-ba3d-4072-84a6-4aa1e7d82182.png"> </details> Known issue: Don't support the [v1 version asciicast files](https://github.com/asciinema/asciinema/blob/develop/doc/asciicast-v1.md), it's a poorly designed version, it does not specify the file extension and uses `*.json` usually, so it's impossible to recognize the files. Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Fix environments for KaTeX and error reporting (#22453)zeripath2023-01-161-2/+4
| | | | | | | | | | | | | | In #22447 it was noticed that display environments were not working correctly. This was due to the setting displayMode not being set. Further it was noticed that the error was not being displayed correctly. This PR fixes both of these issues by forcibly setting the displayMode setting and corrects an error in displayError. Fix #22447 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Add Mermaid copy button, avoid unnecessary tooltip hide (#22225)silverwind2022-12-252-6/+17
| | | | | | | | | | | | | - Add Copy button to mermaid diagrams which copies their source. - Set tippy to not hide on click and avoid tooltip re-creation for temporary tooltips. This avoids hide and show when copying repo url. Popovers still hide the tooltip as usual. <img width="815" alt="Screenshot 2022-12-23 at 14 02 32" src="https://user-images.githubusercontent.com/115237/209341696-98e30953-f246-46d9-9157-2ececfd791c9.png"> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
* Fix markdown anchor re-clicking (#21931)silverwind2022-11-261-6/+9
| | | | | | | | | The hashchange event did not fire on re-click of a active anchor. Instead, use the click event which always fires. Fixes: https://github.com/go-gitea/gitea/issues/21680 Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: zeripath <art27@cantab.net>
* Fix scroll over mermaid frame (#21925)silverwind2022-11-241-1/+1
| | | | | | | | | | When starting a scroll while the mouse is over a mermaid diagram, the scroll sometimes propagates to the iframe, preventing the parent page from scrolling. Fix this by disabling scroll inside the iframe. This is not a problem because those frames are never meant to scroll. Bug seems to affect Firefox only. ![scroll](https://user-images.githubusercontent.com/115237/203847578-6831e3c8-9df4-4577-8501-822fb9ea1278.gif)
* Tweak katex options (#21828)silverwind2022-11-171-4/+6
| | | | | | | | | - Render directly into DOM, skipping string conversion - Add limiting options to prevent excessive size/macros - Remove invalid `display` option previously passed Ref: https://katex.org/docs/options.html Co-authored-by: John Olheiser <john.olheiser@gmail.com>
* Fix opaque background on mermaid diagrams (#21642)silverwind2022-10-311-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | Browsers introduce a opaque background on iframes if the iframe element's color-scheme does not match the document's color scheme which in case of a dark theme results in a mismatch and the browser adds a white background. Avoid this by specifying the same color scheme outside and inside the iframe. See https://fvsch.com/transparent-iframes for more info. My initial attempt was to make the iframe document the same color-scheme as the parent page (light or dark) but with that, there was a ugly background flash on load in Chrome because Chrome apparently always loads iframe in light scheme initially. Firefox still shows a background flash on load but this is not possible to get rid of and it's certainly a browser bug. Before: <img width="1147" alt="Screen Shot 2022-10-31 at 13 30 55" src="https://user-images.githubusercontent.com/115237/199017132-9828aace-bdd0-4ede-8118-359e72bcf2fe.png"> After: <img width="1152" alt="Screen Shot 2022-10-31 at 13 30 36" src="https://user-images.githubusercontent.com/115237/199017137-989a9e67-3fe0-445f-a191-df5bf290dabf.png">
* Fix mermaid-related bugs (#21431)silverwind2022-10-151-1/+1
|
* Add KaTeX rendering to Markdown. (#20571)zeripath2022-09-142-0/+39
| | | | | | | | | | | | | | | | | | | | This PR adds mathematical rendering with KaTeX. The first step is to add a Goldmark extension that detects the latex (and tex) mathematics delimiters. The second step to make this extension only run if math support is enabled. The second step is to then add KaTeX CSS and JS to the head which will load after the dom is rendered. Fix #3445 Signed-off-by: Andrew Thornton <art27@cantab.net> Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Various Mermaid improvements (#18776)silverwind2022-02-161-15/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Various Mermaid improvments - Render into iframe for improved security - Use built-in dark theme instead of color inversion - Remove flexbox attributes, resulting in more consistent size rendering - Update API usage and update to latest version * restart ci * misc tweaks * remove unneccesary declaration * make it work without allow-same-origin, add loading=lazy * remove loading attribute, does not seem to work * rename variable * skip roundtrip to DOM for rendering * don't guess chart height * update comment to make it clear it's intentional * tweak * replace deprecated 'scrolling' property * remove unused css file Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Use explicit jQuery import, remove unused eslint globals (#18435)silverwind2022-01-281-3/+4
| | | | | - Don't rely on globals (window.$) for jQuery import - Remove eslint globals no longer in use
* Add new JS linter rules (#17699)silverwind2021-11-221-4/+5
| | | | | | | | | | | | | | | | | | | | * Add new JS linter rules Adds a few useful rules from eslint-plugin-github. Notable changes: - Forbid dataset usage, its camel-casing behaviour makes it hard to grep for attributes. - Forbid .then() and .catch(), we should generally prefer await for new code. For rare cases where they are useful, a eslint-disable-line directive can be set. - Add docs js to linting * also enable github/array-foreach * small tweak Co-authored-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Add copy button to markdown code blocks (#17638)silverwind2021-11-163-3/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add copy button to markdown code blocks Done mostly in JS because I think it's better not to try getting buttons past the markup sanitizer. * add svg module tests * fix sanitizer regexp * remove outdated comment * vertically center button in issue comments as well * add comment to css * fix undefined on view file line copy * combine animation less files * Update modules/markup/markdown/markdown.go Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> * add test for different sizes * add cloneNode and add tests for it * use deep clone * remove useless optional chaining * remove the svg node cache * unify clipboard copy string and i18n * remove unused var * remove unused localization * minor css tweaks to the button * comment tweak * remove useless attribute Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Improve async/await usage, and sort init calls in `index.js` (#17386)wxiaoguang2021-11-091-2/+2
| | | | * clean up async/await, and sort init calls in `index.js * use `const _promise` to indicate that we do not need await an async function
* Frontend refactor, PascalCase to camelCase, remove unused code (#17365)wxiaoguang2021-10-212-4/+4
| | | | | * Frontend refactor, PascalCase to camelCase, remove unused code * fix
* Update JS dependencies (#17357)silverwind2021-10-191-1/+1
| | | | | | | | | | | | | * Update JS dependencies - Upgrade to eslint 8 and add new plugin rules - Adapt to various API changes - Rebuild SVGs * fix webpack warning on license * order options alphabetically Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Keep attachments on tasklist update (#16750)KN4CK3R2021-08-201-1/+2
| | | | | | | | | | | * Send attachments too. * Use tasklist flag. * use action="ignoreAttachments" instead of "tasklist" * Use boolean parameter. Co-authored-by: zeripath <art27@cantab.net>
* Make Mermaid.js limit configurable (#16519)zeripath2021-07-241-3/+3
| | | | | | | | | | | | | | | | | | | | | | | * Make Mermaid.js limit configurable Add `MERMAID_MAX_SOURCE_CHARACTERS` to `[markup]` settings to make the maximum size of a mermaid render configurable. Fix #16513 Signed-off-by: Andrew Thornton <art27@cantab.net> * fixup! Make Mermaid.js limit configurable * Update custom/conf/app.example.ini Co-authored-by: silverwind <me@silverwind.io> * Update docs/content/doc/advanced/config-cheat-sheet.en-us.md Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Fixed setting of wrong position (#16148)KN4CK3R2021-06-141-3/+13
|
* Make tasklist checkboxes clickable (#15791)KN4CK3R2021-05-232-1/+70
| | | | Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Lauris BH <lauris@nix.lv>
* Use a generic markup class to display externally rendered files and diffs ↵65432021-05-073-0/+93
(#15735) * creates and implements generic markup less class * How to give custom CSS to externally rendered html * Clarifies sources of CSS styling of markup * further clarification of sources of markup styling * rename _markdown to _markup * remove defunct import * fix orphaned reference * Update docs/content/doc/advanced/external-renderers.en-us.md * more renames markdown -> markup * do not suggest less customization * add back tokens * fix class whitespace, remove useless if-clause * remove unused csv-data rules * use named exports and rename functions * sort imports Co-authored-by: HarvsG <11440490+HarvsG@users.noreply.github.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: silverwind <me@silverwind.io>