aboutsummaryrefslogtreecommitdiffstats
path: root/modules/markup
Commit message (Collapse)AuthorAgeFilesLines
...
* Make pasted "img" tag has the same behavior as markdown image (#31235)wxiaoguang2024-06-044-58/+74
| | | | | | | Fix #31230 --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
* Split sanitizer functions and fine-tune some tests (#31192)wxiaoguang2024-05-318-245/+270
|
* Use repo as of renderctx's member rather than a repoPath on metas (#29222)Lunny Xiao2024-05-306-39/+99
| | | | Use a `gitrepo.Repository` in the markup's RenderContext but not store the repository's path.
* Refactor AppURL usage (#30885)wxiaoguang2024-05-071-1/+1
| | | | | | | | Fix #30883 Fix #29591 --------- Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
* Fix markdown URL parsing for commit ID (#30812)wxiaoguang2024-05-044-74/+115
|
* Fix markdown rendering when mentioning users (#30795)wxiaoguang2024-05-021-8/+7
|
* Resolve lint for unused parameter and unnecessary type arguments (#30750)Chongyi Zheng2024-04-297-13/+10
| | | | | | | | | | Resolve all cases for `unused parameter` and `unnecessary type arguments` Related: #30729 --------- Co-authored-by: Giteabot <teabot@gitea.io>
* Enable more `revive` linter rules (#30608)silverwind2024-04-221-2/+0
| | | | | | | | | | | Noteable additions: - `redefines-builtin-id` forbid variable names that shadow go builtins - `empty-lines` remove unnecessary empty lines that `gofumpt` does not remove for some reason - `superfluous-else` eliminate more superfluous `else` branches Rules are also sorted alphabetically and I cleaned up various parts of `.golangci.yml`.
* Use raw Wiki links for non-renderable Wiki files (#30273)Rafael2024-04-104-16/+55
| | | | | | | | | | | | | | | | | | | In Wiki pages, short-links created to local Wiki files were always expanded as regular Wiki Links. In particular, if a link wanted to point to a file that Gitea doesn't know how to render (e.g, a .zip file), a user following the link would be silently redirected to the Wiki's home page. This change makes short-links* in Wiki pages be expanded to raw wiki links, so these local wiki files may be accessed without manually accessing their URL. * only short-links ending in a file extension that isn't renderable are affected. Closes #27121. Signed-off-by: Rafael Girão <rafael.s.girao@tecnico.ulisboa.pt> Co-authored-by: silverwind <me@silverwind.io>
* Fix code block style for code preview (#30298)wxiaoguang2024-04-061-1/+1
| | | | | Fix #30292 To avoid unnecessary style overriding, use "div" instead of "code"
* Fixes #27605: inline math blocks can't be preceeded/followed by ↵João Tiago2024-04-022-7/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | alphanumerical characters (#30175) - Inline math blocks couldn't be preceeded or succeeded by alphanumerical characters due to changes introduced in PR #21171. Removed the condition that caused this (precedingCharacter condition) and added a new exit condition of the for-loop that checks if a specific '$' was escaped using '\' so that the math expression can be rendered as intended. - Additionally this PR fixes another bug where math blocks of the type '$xyz$abc$' where the dollar sign was not escaped by the user, generated an error (shown in the screenshots below) - Altered the tests to accomodate for the changes Former behaviour (from try.gitea.io): ![image](https://github.com/go-gitea/gitea/assets/114936010/8f0cbb21-321d-451c-b871-c67a8e1e9235) Fixed behaviour (from my local build): ![image](https://github.com/go-gitea/gitea/assets/114936010/5c22687c-6f11-4407-b5e7-c14b838bc20d) (Edit) Source code for the README.md file: ``` $x$ -$x$ $x$- a$xa$ $xa$a 1$xb$ $xb$1 $a a$b b$ a$b $a a$b b$ $a a\$b b$ ``` --------- Signed-off-by: João Tiago <joao.leal.tintas@tecnico.ulisboa.pt> Co-authored-by: Giteabot <teabot@gitea.io>
* Render embedded code preview by permlink in markdown (#30234)wxiaoguang2024-04-025-0/+145
| | | | | The permlink in markdown will be rendered as a code preview block, like GitHub Co-authored-by: silverwind <me@silverwind.io>
* Fix markdown color code detection (#30208)wxiaoguang2024-03-312-3/+26
| | | | | When reviewing PRs, some color names might be mentioned, the `transformCodeSpan` (which calls `css.ColorHandler`) considered it as a valid color, but actually it shouldn't be rendered as a color codespan.
* Refactor markdown render (#30139)wxiaoguang2024-03-288-257/+364
| | | | Only split the file into small ones (and rename AttentionTypes to attentionTypes)
* Fix bug for markdown rendering of blockquote (#30130)Lunny Xiao2024-03-271-4/+10
| | | | | | | Caused by #29984 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Refactor markdown attention render (#29984)wxiaoguang2024-03-224-64/+128
| | | Follow #29833 and add tests
* Fix some pending problems (#29985)wxiaoguang2024-03-221-3/+2
| | | | | | | | | | | | | | | | | These changes are quite independent and trivial, so I don't want to open too many PRs. * https://github.com/go-gitea/gitea/pull/29882#discussion_r1529607091 * the `f.Close` should be called properly * the error message could be more meaningful (https://github.com/go-gitea/gitea/pull/29882#pullrequestreview-1942557935) * https://github.com/go-gitea/gitea/pull/29859#pullrequestreview-1942324716 * the new translation strings don't take arguments * https://github.com/go-gitea/gitea/pull/28710#discussion_r1443778807 * stale for long time * #28140 * a form was forgotten to be changed to work with backend code
* Fix missing error check of bufio.Scanner (#29882)coldWater2024-03-191-0/+5
| | | maybe more
* Refactor markdown attention render (#29833)wxiaoguang2024-03-163-32/+12
| | | | | | | * Remove some deadcode * Use 2-word name for CSS class names * Remove "gt-*" rules for sanitizer The UI doesn't change much.
* Refactor markup/csv: don't read all to memory (#29760)coldWater2024-03-142-12/+55
|
* Use relative links for commits, mentions, and issues in markdown (#29427)KN4CK3R2024-03-135-15/+27
| | | | | | | | | | | | Fixes #29404 Use relative links for - commits - mentions - issues --------- Co-authored-by: silverwind <me@silverwind.io>
* Fix inconsistent rendering of block mathematical expressions (#29677)yp053272024-03-111-1/+2
| | | | | | | | | | | | | | | | Fix #28735 GitHub render `\```math\``` ` as a block now. Add `display` class will render it as a block. After: ![image](https://github.com/go-gitea/gitea/assets/18380374/2a1c20c7-438e-4ab1-8c66-cf91c8343087) ![image](https://github.com/go-gitea/gitea/assets/18380374/b81b8a93-8bca-46a5-b7db-e0d2f53e1342) --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* fix: rendering internal file links in org (#29669)Ankit R Gadiya2024-03-102-4/+38
| | | | | | | | The internal links to other files in the repository were not rendering with the Src Prefix (/src/branch-name/file-path). This commit fixes that by using the `SrcLink` as base if available. Resolves #29668
* Don't use `<br />` in alert block (#29650)Yarden Shoham2024-03-081-8/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Follows https://github.com/go-gitea/gitea/pull/29121 When I implemented alert blocks I was always testing the markdown in issue comments. I used `<br />` for line breaks and it looked good. I have since learned that the markdown on README files doesn't allow these tags. So a comment with ```md > [!NOTE] > If you're interested in using our APIs, we have experimental support with [documentation](https://try.gitea.io/api/swagger). ``` looked like this in a comment ![image](https://github.com/go-gitea/gitea/assets/20454870/96b1de01-2c87-4d4f-83dd-98192b83e9d0) but looked like this in a README ![image](https://github.com/go-gitea/gitea/assets/20454870/474b636d-dd7a-4b7f-ba27-643803c71aa3) So I changed how we render the alert block by having the alert itself have a dedicated paragraph, so line breaks happen naturally between paragraphs. # Before ![image](https://github.com/go-gitea/gitea/assets/20454870/474b636d-dd7a-4b7f-ba27-643803c71aa3) ![image](https://github.com/go-gitea/gitea/assets/20454870/167a8d37-9a44-4479-9340-5dc80347b595) # After ![image](https://github.com/go-gitea/gitea/assets/20454870/2f99fec0-98ff-4ba8-97fe-b4567041ae79) ![image](https://github.com/go-gitea/gitea/assets/20454870/ffdeae11-fb06-4d00-b497-eae135f0d7ad) --------- Signed-off-by: Yarden Shoham <git@yardenshoham.com> Co-authored-by: silverwind <me@silverwind.io>
* Fix incorrect rendering csv file when file size is larger than ↵yp053272024-03-081-2/+4
| | | | | UI.CSV.MaxFileSize (#29653) Fix #29506
* Refactor some Str2html code (#29397)wxiaoguang2024-03-013-20/+23
| | | | | | | | | | | | | | | This PR touches the most interesting part of the "template refactoring". 1. Unclear variable type. Especially for "web/feed/convert.go": sometimes it uses text, sometimes it uses HTML. 2. Assign text content to "RenderedContent" field, for example: ` project.RenderedContent = project.Description` in web/org/projects.go 3. Assign rendered content to text field, for example: `r.Note = rendered content` in web/repo/release.go 4. (possible) Incorrectly calling `{{Str2html .PackageDescriptor.Metadata.ReleaseNotes}}` in package/content/nuget.tmpl, I guess the name Str2html misleads developers to use it to "render string to html", but it only sanitizes. if ReleaseNotes really contains HTML, then this is not a problem.
* Fix wrong test usage of `AppSubURL` (#29459)KN4CK3R2024-02-291-22/+17
| | | | The tests use an invalid `setting.AppSubURL`. The wrong behaviour disturbs other PRs like #29222 and #29427.
* Refactor markup rendering to accept general "protocol:" prefix (#29276)wxiaoguang2024-02-214-32/+38
| | | | | | | | | | | | Follow #29024 Major changes: * refactor validLinksPattern to fullURLPattern and add comments, now it accepts "protocol:" prefix * rename `IsLink*` to `IsFullURL*`, and remove unnecessray "mailto:" check * fix some comments (by the way) * rename EmojiShortCodeRegex -> emojiShortCodeRegex (by the way)
* Refactor locale&string&template related code (#29165)wxiaoguang2024-02-142-2/+2
| | | | | | Clarify when "string" should be used (and be escaped), and when "template.HTML" should be used (no need to escape) And help PRs like #29059 , to render the error messages correctly.
* Add alert blocks in markdown (#29121)Yarden Shoham2024-02-103-24/+65
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Follows https://github.com/go-gitea/gitea/pull/21711 - Closes https://github.com/go-gitea/gitea/issues/28316 Implement GitHub's alert blocks markdown feature Docs: - https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts - https://github.com/orgs/community/discussions/16925 ### Before ![image](https://github.com/go-gitea/gitea/assets/20454870/14f7b02a-5de5-4fd0-8437-a055dadb31f2) ### After ![image](https://github.com/go-gitea/gitea/assets/20454870/ed06a869-e545-42f1-bf25-4ba20b1be196) ## :warning: BREAKING :warning: The old syntax no longer works How to migrate: If you used ```md > **Note** My note ``` Switch to ```md > [!NOTE] > My note ``` --------- Signed-off-by: Yarden Shoham <git@yardenshoham.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Giteabot <teabot@gitea.io>
* Fix orgmode link resolving (#29024)wxiaoguang2024-02-072-39/+41
| | | | | Fix #28974 Add some new tests and fix some legacy unclear tests.
* Update tool dependencies (#29030)silverwind2024-02-021-1/+0
|
* Strip `/` from relative links (#28932)KN4CK3R2024-01-272-4/+32
| | | | | | | Fixes #28915 Restores the old behaviour: https://github.com/go-gitea/gitea/pull/26745/files#diff-d78a9d361b1fddc12218e4dd42f42d39d6be1fda184041e06bb6fb30f0d94c59L96
* Respect branch info for relative links (#28909)KN4CK3R2024-01-252-2/+4
| | | | | Fix #28904 Co-authored-by: Giteabot <teabot@gitea.io>
* Add support for sha256 repositories (#23894)Adam Majer2024-01-192-21/+21
| | | | | | | | | | | | | | | | Currently only SHA1 repositories are supported by Gitea. This adds support for alternate SHA256 with the additional aim of easier support for additional hash types in the future. Fixes: #13794 Limited by: https://github.com/go-git/go-git/issues/899 Depend on: #28138 <img width="776" alt="图片" src="https://github.com/go-gitea/gitea/assets/81045/5448c9a7-608e-4341-a149-5dd0069c9447"> --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: 6543 <6543@obermui.de>
* Rework markup link rendering (#26745)KN4CK3R2024-01-1510-194/+596
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes #26548 This PR refactors the rendering of markup links. The old code uses `strings.Replace` to change some urls while the new code uses more context to decide which link should be generated. The added tests should ensure the same output for the old and new behaviour (besides the bug). We may need to refactor the rendering a bit more to make it clear how the different helper methods render the input string. There are lots of options (resolve links / images / mentions / git hashes / emojis / ...) but you don't really know what helper uses which options. For example, we currently support images in the user description which should not be allowed I think: <details> <summary>Profile</summary> https://try.gitea.io/KN4CK3R ![grafik](https://github.com/go-gitea/gitea/assets/1666336/109ae422-496d-4200-b52e-b3a528f553e5) </details> --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
* Make cross-reference issue links work in markdown documents again (#28682)Brecht Van Lommel2024-01-032-5/+13
| | | | | | | | | | In #26365 issue references were disabled entirely for documents, intending to match GitHub behavior. However cross-references do appear to work in documents on GitHub. This is useful for example to write release notes in a markdown document and reference issues. While the simpler syntax may create links when not intended, hopefully the cross-reference syntax is unique enough to avoid it.
* Fix the issue ref rendering for wiki (#28556)wxiaoguang2023-12-201-1/+3
| | | | | | | | Fix #28526, regression of * #26365 (although the author of #26365 has recent activities, but there is no response for the regression, so I proposed this quick fix and keep the fix simple to make it easier to backport to 1.21)
* Add option to disable ambiguous unicode characters detection (#28454)wxiaoguang2023-12-171-1/+1
| | | | | | | | * Close #24483 * Close #28123 * Close #23682 * Close #23149 (maybe more)
* Use restricted sanitizer for repository description (#28141)Earl Warren2023-11-232-3/+54
| | | | | | | | | | | | | | | - Currently the repository description uses the same sanitizer as a normal markdown document. This means that element such as heading and images are allowed and can be abused. - Create a minimal restricted sanitizer for the repository description, which only allows what the postprocessor currently allows, which are links and emojis. - Added unit testing. - Resolves https://codeberg.org/forgejo/forgejo/issues/1202 - Resolves https://codeberg.org/Codeberg/Community/issues/1122 (cherry picked from commit 631c87cc2347f0036a75dcd21e24429bbca28207) Co-authored-by: Gusted <postmaster@gusted.xyz>
* Render email addresses as such if followed by punctuation (#27987)Yarden Shoham2023-11-112-1/+13
| | | | | | | | | | | | | | | | | | | | | | Added the following characters to the regular expression for the email: - , - ; - ? - ! Also added a test case. - Fixes #27616 # Before ![image](https://github.com/go-gitea/gitea/assets/20454870/c57eac26-f281-43ef-a51d-9c9a81b63efa) # After ![image](https://github.com/go-gitea/gitea/assets/20454870/fc7d5c08-4350-4af0-a7f0-d1444d2d75af) Signed-off-by: Yarden Shoham <git@yardenshoham.com>
* Remove `title` from elements on Org mode (#27968)KN4CK3R2023-11-102-11/+15
| | | | | | | | | | | | | | | | The Org mode rendering has some problems: 1. `[[https://example.com][pre https://example.com/example.mp4 post]]` renders as `<p><a href="https://example.com" title="pre <video src="https://example.com/example.mp4" title="https://example.com/example.mp4">https://example.com/example.mp4</video> post">pre <video src="https://example.com/example.mp4" title="https://example.com/example.mp4">https://example.com/example.mp4</video> post</a></p>` As you can see, the `title` attribute contains the inner html in unescaped form. I removed the `title` attribute because it is of little value. 3. The `title` attribute on `img` and `video` is of little value. 4. The inner elements of `video` are different depending on the `if`.
* Upgrade to golangci-lint@v1.55.0 (#27756)silverwind2023-10-242-83/+83
| | | https://github.com/golangci/golangci-lint/releases/tag/v1.55.0
* fix media description render for orgmode (#26895)Earl Warren2023-09-132-9/+34
| | | | | | | | | | | | | | | - In org mode you can specify an description for media via the following syntax `[[description][media link]]`. The description is then used as title or alt. - This patch fixes the rendering of the description by seperating the description and non-description cases and using `org.String()`. - Added unit tests. - Inspired by https://github.com/niklasfasching/go-org/blob/6eb20dbda93cb88c3503f7508dc78cbbc639378f/org/html_writer.go#L406-L427 - Resolves https://codeberg.org/Codeberg/Community/issues/848 (cherry picked from commit 8b8aab83113b34bade61964e2097ed497abc39e9) Co-authored-by: Gusted <postmaster@gusted.xyz>
* Make `user-content-* ` consistent with github (#26388)CaiCandong2023-08-092-9/+64
| | | | | | Fix #26367 Related #19745 Thanks @lazyky for providing test cases
* Do not highlight `#number` in documents (#26365)Earl Warren2023-08-073-1/+61
| | | | | | | | | | | | | | - Currently the post processing will transform all issue indexes (such as `#6`) into a clickable link. - This makes sense in an situation like issues or PRs, where referencing to other issues is quite common and only referencing their issue index is an handy and efficient way to do it. - Currently this is also run for documents (which is the user profile and viewing rendered files), but in those situations it's less common to reference issues by their index and instead could mean something else. - This patch disables this post processing for issue index for documents. Matches Github's behavior. - Added unit tests. - Resolves https://codeberg.org/Codeberg/Community/issues/1120 Co-authored-by: Gusted <postmaster@gusted.xyz>
* Render plaintext task list items for markdown files (#26186)Earl Warren2023-07-272-0/+8
| | | | | | | | | | | | | | - The library that's being used for org-mode, [doesn't render the status of list items](https://github.com/niklasfasching/go-org/issues/63). - Add a modified version of the proposed CSS snippet to still display the status for the list items. The alternative was parsing HTML and transforming it, which is too complicated for this small task. - Resolves https://codeberg.org/Codeberg/Community/issues/1099 (cherry picked from commit 9753c7e4b8490b8f1e3d19cb06187503b88afb88) Refs: https://codeberg.org/forgejo/forgejo/pulls/1071 Co-authored-by: Gusted <postmaster@gusted.xyz>
* Disallow dangerous url schemes (#25960)KN4CK3R2023-07-182-2/+16
| | | | | | | | | | | | Regression: https://github.com/go-gitea/gitea/pull/24805 Closes: #25945 - Disallow `javascript`, `vbscript` and `data` (data uri images still work) url schemes even if all other schemes are allowed - Fixed older `cbthunderlink` tests --------- Co-authored-by: delvh <dev.lh@web.de>
* Upgrade go dependencies (#25819)harryzcy2023-07-141-1/+1
|
* Replace `interface{}` with `any` (#25686)silverwind2023-07-042-5/+5
| | | | | Result of running `perl -p -i -e 's#interface\{\}#any#g' **/*` and `make fmt`. Basically the same [as golang did](https://github.com/golang/go/commit/2580d0e08d5e9f979b943758d3c49877fb2324cb).