summaryrefslogtreecommitdiff
path: root/lib/banzai
Commit message (Collapse)AuthorAgeFilesLines
* Fix description and GFM pipelines conflictingfix-markdown-specSean McGivern2016-06-131-12/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Consider this command: bundle exec rails r "include GitlabMarkdownHelper puts markdown('<span>this is a span</span>', pipeline: :description) puts markdown('<span>this is a span</span>')" And the same in the opposite order: bundle exec rails r "include GitlabMarkdownHelper puts markdown('<span>this is a span</span>') puts markdown('<span>this is a span</span>', pipeline: :description)" Before this change, they would both output: <p><span>this is a span</span></p> <p>this is a span</p> That's because `span` is added to the list of whitelisted elements in the `SanitizationFilter`, but this method tries not to make the same changes multiple times. Unfortunately, `HTML::Pipeline::SanitizationFilter::LIMITED`, which is used by the `DescriptionPipeline`, uses the same Ruby objects for all of its hash values _except_ `:elements`. That means that whichever of `DescriptionPipeline` and `GfmPipeline` is called first would have `span` in its whitelisted elements, and the second wouldn't. Fix this by creating an entirely separate hash, before either pipeline is invoked.
* Merge branch '18019-fix-wiki-linking' into 'master' Rémy Coutable2016-06-092-26/+46
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix wiki linking behavior for markdown wiki pages Related to #18019 - As per the documentation in !4372 ## TODO - [ ] !4432 Have wiki linking behave as per the documentation - [x] Move `WikiLinkFilter` specs to the pipeline level - [x] Verify current behavior on wiki `show` page - [x] Fix current behavior on wiki `show` page - [x] Verify current behaviour on wiki preview - [x] Fix current behaviour on wiki preview - [x] Rewrite all links and get preview links working - [x] Make sure all links are on-par with the wiki `show` page - [x] TDD `WikiLinkFilter` and get it working - [x] Hook `WikiLinkFilter` up - [x] Fix tests - [x] Fix `markdown_spec` - [x] Fix `wiki` spinach feature - [x] Wait for [build](https://gitlab.com/gitlab-org/gitlab-ce/commit/4f50dd2/builds) to pass - [x] Make sure all wiki-related pages are working as expected (history, all pages, etc.) - [x] Test in different ruby versions - [x] GitLab instances hosted on a relative URL - [x] Non-markdown rendering formats? - [x] RDoc - [x] ASCIIDoc - [x] Create issues to fix things for RDoc and ASCIIDoc - [x] Gauge performance impact - [x] Refactor - [x] Re-organize commits - [x] Make sure [build](https://gitlab.com/gitlab-org/gitlab-ce/commit/f860e9a8dcabe7d5f160c32fc549807c98baa4a1/builds) passes - [x] Respond to @rymai's comments - [x] `class WikiLinkFilter < HTML::Pipeline::Filter` - [x] blank line after guard clause - [x] keyword arguments for `wiki` and `slug` - [x] invert the condition - [x] inline `user` in spec - [x] Make sure spec names are not out of date - [x] Comment for each rewrite rule - [x] Add CHANGELOG entry - [x] Reorganize commits - [x] Make sure [build](https://gitlab.com/gitlab-org/gitlab-ce/commit/19b91e749a6320d12fb299d33f1f6440777e0e26/builds) passes - [ ] Wait for merge See merge request !4432
| * Implement the correct linking behaviour in `WikiLinkFilter`.Timothy Andrew2016-06-092-26/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Original Comments ================= - Linking behaves as per rules documented here: https://gitlab.com/gitlab-org/gitlab-ce/blob/16568-document-wiki-linking-behavior/doc/markdown/wiki.md - All links (to other wiki pages) are rewritten to be at the level of the app root. We can't use links relative to the current page ('./foo', 'foo', '../foo'), because they won't work in the markdown preview, where the current page is suffixed with `/edit` - Move existing `WikiLinkFilter` specs to `WikiPipeline` spec. It makes sense to run these tests on the combined output of the pipeline, rather than a single filter, since we can catch issues with conflicting filters. - Add more tests to cover the new linking @rymai's Review =============== - Classes nested under `WikiLinkFilter` should declare `WikiLinkFilter`'s inherit, so nothing changes if the nested class is loaded first. - Add a blank line after a guard clause - Use keyword arguments for the `Rewriter` constructor - Invert a condition - use `if` instead of `unless` - Inline a `let` in `WikiPipeline` spec - it was only used in a single place - Change out of date spec names - Add a comment for every rewrite rule in `Rewriter`
* | Remove obvious comment and extra lineAlfredo Sumaran2016-06-081-2/+0
| |
* | Set target="_blank" for external linksAlfredo Sumaran2016-06-081-0/+3
| |
* | Merge branch 'banzai-user-filter-queries'Douwe Maan2016-06-032-2/+34
|\ \
| * | Reduce Namespace queries in UserReferenceFilterbanzai-user-filter-queriesYorick Peterse2016-06-021-2/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This changes UserReferenceFilter so it operates using the following steps: 1. Grab all username references from the input document. 2. Query the corresponding Namespace objects using a single query. 3. Iterate over all nodes to build links while re-using the objects queried in step 2. The impact of these changes is that a comment mentioning 5 different usernames no longer runs 5 different queries (1 for every username), instead it only runs a single query.
| * | Added ReferenceFilter#nodesYorick Peterse2016-06-021-0/+5
| | | | | | | | | | | | | | | | | | This method returns an Array of the HTML nodes as yielded by ReferenceFilter#each_node. The method's return value is memoized to allow multiple calls without having to re-query the input document.
| * | Returning enums in ReferenceFilter#each_nodeYorick Peterse2016-06-021-0/+2
| |/ | | | | | | | | This changes ReferenceFilter#each_node so that when it's called without a block an Enumerator is returned.
* | Fix serious performance bug with rendering Markdown with InlineDiffFilterStan Hu2016-06-011-4/+8
|/ | | | | | | | | Nokogiri's `node.replace` was being unnecessarily called for every text node in the document due to a comparison bug. The code previously was comparing the HTML representation of the full document against the text node, which would always fail. Fix the comparison to just compare the modified text. Closes #18011
* Merge branch 'separate-banzai-references' into 'master' Douwe Maan2016-06-0127-265/+554
|\ | | | | | | | | | | | | | | | | Separate reference gathering from rendering This is a required step to allow batch processing when gathering references. This in turn would allow grabbing (for example) all mentioned users of an issue/merge request using a single query. cc @rspeicher @DouweM See merge request !3969
| * Split Markdown rendering & reference gatheringYorick Peterse2016-05-2627-265/+554
| | | | | | | | | | | | | | | | | | | | This splits the Markdown rendering and reference extraction phases into two distinct code bases. The reference extraction phase no longer relies on the html-pipeline Gem (and any related code) and allows for extracting of references from multiple HTML nodes in a single pass. This means that if you want to extract user references from 200 comments you no longer need to run 200 times N number of queries, instead only a handful of queries may be needed.
* | Fix 404 page when viewing TODOs that contain milestones or labels in ↵Stan Hu2016-05-311-1/+3
|/ | | | | | | | | | | | | | | | | | | | | different projects A user viewing the TODOs page will see a 404 if there are mentioned labels in multiple different projects. This is likely a caching bug and only occurs when Markdown rendering occurs across multiple projects, which is why it's so tricky to reproduce. This is what I think is happening: 1. LabelReferenceFilter#references_in encounters label ~X for ProjectA and finds the label in the DB as id = 1. 2. LabelReferenceFilter.references_in yields [1, 'X', nil, ...] 3. Since project_ref is nil, AbstractReferenceFilter#project_from_ref_cache caches nil => ProjectA. 4. LabelReferenceFilter#references_in encounters label ~Y for ProjectB and finds the label in the DB as id = 2. 5. LabelReferenceFilter.references_in yields [2, 'Y', nil, ...] 6. AbstractReferenceFilter#project_from_ref_cache lookups nil and returns ProjectA. It was supposed to be ProjectB. 7. A is the wrong project, so the label lookup fails. This MR caches Markdown references if the key is present. Closes #17898
* Merge branch 'adambutler/gitlab-ce-feature/support-diff-of-issue-title-rename'Douwe Maan2016-05-202-1/+24
|\ | | | | | | | | # Conflicts: # app/services/system_note_service.rb
| * Create DiffFilter and change SystemNoteService#change_title to use ↵Adam Butler2016-05-182-1/+24
| | | | | | | | Gitlab::Diff::InlineDiff
* | Merge remote-tracking branch 'origin/master' into ↵Rémy Coutable2016-05-184-5/+19
|\ \ | |/ | | | | | | | | eReGeBe/gitlab-ce-feature/milestone-md Signed-off-by: Rémy Coutable <remy@rymai.me>
| * Add a spec for `WikiLinkFilter`Timothy Andrew2016-05-121-3/+8
| | | | | | | | - And fix behavior for non-file hierarchical links.
| * Merge branch 'fix/using-uploads-in-global-snippets' into 'master' Robert Speicher2016-05-101-1/+7
| |\ | | | | | | | | | | | | | | | | | | Fix using link to uploads in global snippets Closes #17342, closes #17363 See merge request !4085
| | * Do not process upload links if no project contextGrzegorz Bizon2016-05-101-2/+6
| | |
| | * Fix using link to uploads in global snippetsGrzegorz Bizon2016-05-101-1/+3
| | | | | | | | | | | | Closes #17342, closes #17363
| * | Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ceDmitriy Zaporozhets2016-05-101-0/+3
| |\ \
| | * | Links for redmine issue references are generated correctly againBenedikt Huss2016-05-101-0/+3
| | |/
| * | Use a case-insensitive comparison in sanitizing URI schemesStan Hu2016-05-091-1/+1
| |/ | | | | | | Closes #1625
* | Fix cross-project milestone ref with invalid projectDouwe Maan2016-04-231-11/+17
| |
* | Merge branch 'master' into eReGeBe/gitlab-ce-feature/milestone-mdDouwe Maan2016-04-232-18/+23
|\ \ | |/
| * Merge branch 'dev_issue_15331' into 'master' Robert Speicher2016-04-211-3/+2
| |\ | | | | | | | | | | | | | | | | | | | | | | | | Fixes window.opener bug Adds `noreferrer` value to rel attribute for external links REF: https://gitlab.com/gitlab-org/gitlab-ce/issues/15331 See merge request !1953
| | * Fix failing specAlfredo Sumaran2016-04-211-2/+1
| | |
| | * Add noreferrer value to rel attribute for external linksAlfredo Sumaran2016-04-201-1/+1
| | |
| * | Refactor banzai code that finds cross-project labelsGrzegorz Bizon2016-04-211-15/+21
| | |
| * | Fix cross-project label ref with invalid projectGrzegorz Bizon2016-04-211-1/+1
| |/ | | | | | | Closes #15168
* | Using project `path_with_namespace` in milestone's cross project references ↵Alejandro Rodríguez2016-04-201-1/+1
| | | | | | | | link text
* | Escaping the `object_link_text` on cross project milestone referencesAlejandro Rodríguez2016-04-201-1/+1
| |
* | Transforming milestones link references to the short reference formAlejandro Rodríguez2016-04-201-0/+5
| |
* | Consistently using iid when treating milestones as referrablesAlejandro Rodríguez2016-04-201-5/+14
| | | | | | | | Also, addint a suffix to the reference text when the milestone is in another project
* | Implementing special GitLab markdown reference for milestonesAlejandro Rodríguez2016-04-201-2/+24
|/ | | | | Using the syntax proposed in #13829 [project_reference]%(milestone_id | milestone_name) to get a link to the referred milestone.
* Instrument Banzai codeYorick Peterse2016-04-111-8/+12
|
* Merge branch 'patch/fix-markdown-preview-wikis' into 'master' Robert Speicher2016-04-073-6/+70
|\ | | | | | | | | | | | | | | | | | | | | Wiki preview URL converting problem [via Markdown] Current implementation when rendering the preview, thinks relative links are for project repository files. We are creating a new preview route that will define correct context data to render for wikis instead. Fixes #2380, #1184 See merge request !3461
| * little refactor and improvements on specsGabriel Mazetto2016-04-061-6/+2
| |
| * Ensure correct filter order to validate with our markdown specpatch/fix-markdown-preview-wikisGabriel Mazetto2016-04-062-3/+7
| |
| * Fix a few edited references from WikiLinkFilter and specsGabriel Mazetto2016-04-061-2/+6
| |
| * Fixed WikiPipeline and specsGabriel Mazetto2016-04-061-1/+1
| |
| * Added WikiLinkFilterGabriel Mazetto2016-04-012-2/+56
| |
| * Fixed Gollum pages link url expansion to render correctly in previewGabriel Mazetto2016-03-301-3/+9
| |
* | Fix header link rendering when containing numbersfix-markdown-renderingYorick Peterse2016-04-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | This fixes the problem where Markdown such as: ### 31st Would get rendered as a link tag pointing to issue number 31 inside a header tag. See gitlab-org/gitlab-ce#14936 for more information.
* | Wrap images in discussions and wikis with a link to the image source using ↵connorshea2016-04-042-0/+28
| | | | | | | | | | | | | | | | ImageLinkFilter. Resolves #14411. See merge request !3464
* | Cleaned up caching in AbstractReferenceFilterYorick Peterse2016-04-041-15/+11
| | | | | | | | | | Cleaning this up any further is a bit tricky as the caches in question should only be evaluated if RequestStore is actually enabled.
* | Cache default_issues_tracker? in BanzaiYorick Peterse2016-04-041-1/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Every object processed by ExternalIssueReferenceFilter can return a different Project instance when calling "project". For example, every note processed will have it's own associated Project. If we were to cache Project#default_issues_tracker? on Project level this would have no impact on Markdown rendering timings as the cache would have to be built for every Project instance without it ever being re-used. To work around this we cache Project#default_issues_tracker? in Banzai::Filter::ExternalIssueReferenceFilter using the project's _id_ instead of the whole object. This setup allows re-using of the cached data even when the Project instances used are different, as long as the actual project IDs are the same.
* | Memoize object class titlesYorick Peterse2016-04-041-1/+9
| | | | | | | | | | For an issue with around 200 notes this cuts down timings by around 150 milliseconds.
* | Cache Banzai class methods returning static dataYorick Peterse2016-04-041-3/+3
| | | | | | | | | | These methods always return the same data for every class so there's no point in computing their values on every call.
* | Refactor processing of various Banzai filtersYorick Peterse2016-04-044-134/+120
| | | | | | | | | | | | | | These filters now use a single iteration over all the document nodes instead of multiple ones. This in turn allows variables to be re-used (e.g. links only have to be unescaped once). Combined with some other refactoring this can drastically reduce render timings.