summaryrefslogtreecommitdiff
path: root/lib/banzai
Commit message (Collapse)AuthorAgeFilesLines
* Wrap images in divs with Banzai and limit max-height.image-sizingConnor Shea2016-06-271-1/+9
| | | | | | Add max-height to prevent images from displaying larger than the provided screen size. Also fix a failing test and add a new one.
* Support for rendering/redacting multiple documentsYorick Peterse2016-06-245-28/+188
| | | | | | | | | | | | | | | | | | | | | | | | | | This commit changes the way certain documents are rendered (currently only Notes) and how documents are redacted. Previously both rendering and redacting would run on a per document basis. The result of this was that for every document we'd have to run countless queries just to figure out if we could display a set of links or not. This commit changes things around so that redacting Markdown documents is no longer tied into the html-pipeline Gem. This in turn allows it to redact multiple documents in a single pass, thus reducing the number of queries needed. In turn rendering issue/merge request notes has been adjusted to take advantage of this new setup. Instead of rendering Markdown somewhere deep down in a view the Markdown is rendered and redacted in the controller (taking the current user and all that into account). This has been done in such a way that the "markdown()" helper method can still be used on its own. This particular commit also paves the way for caching rendered HTML on object level. Right now there's an accessor method Note#note_html which is used for setting/getting the rendered HTML. Once we cache HTML on row level we can simply change this field to be a column and call a "save" whenever needed and we're pretty much done.
* Merge branch 'fix-external-issue-links' into 'master' Robert Speicher2016-06-221-3/+7
|\ | | | | | | | | | | | | | | | | | | Handle external issues in IssueReferenceFilter Handling of external issues was broken when I refactored `IssueReferenceFilter` to use fewer SQL queries. Fixes #18827 See merge request !4789
| * Handle external issues in IssueReferenceFilterfix-external-issue-linksYorick Peterse2016-06-211-3/+7
| | | | | | | | | | | | | | | | | | | | | | In the past this class would use Project#get_issue to retrieve an issue by its ID. This method would automatically determine whether to return an Issue or ExternalIssue. This commit changes IssueReferenceFilter to handle external issues again and in a somewhat more explicit manner than before. Fixes gitlab-org/gitlab-ce#18827
* | Merge branch 'remove-banzai-pre-process' into 'master' Robert Speicher2016-06-211-6/+2
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | Move pre_process into render_result This MR moves `Banzai::Renderer.pre_process` into `Banzai::Renderer.render_result`. The `pre_process` method was called even when its output would be ignored. See 11a5a4f359ee57029dbfcc9185fc6b47243ea2aa for more details. See merge request !4830
| * | Move pre_process into render_resultremove-banzai-pre-processYorick Peterse2016-06-211-6/+2
| |/ | | | | | | | | | | | | | | | | | | | | The method Banzai::Renderer.pre_process would always be called, regardless of whether the Markdown to render was already cached or not. In cache the document _was_ cached the output of the pre-processing pipeline was ignored resulting in it doing nothing but wasting CPU cycles. This commit moves Banzai::Renderer.pre_process into Banzai::Renderer.render_result so that it's _only_ used when needed.
* | Optimize Banzai::Filter::RelativeLinkFilterAlejandro Rodríguez2016-06-211-37/+14
|/ | | | | | | | | | | | A lot of git operations were being repeated, for example, to build a url you would ask if the path was a Tree, which would call a recursive routine in Gitlab::Git::Tree#where, then ask if the path was a Blob, which would call a recursive routine at Gitlab::Git::Blob#find, making reference to the same git objects several times. Now we call Rugged::Tree#path, which allows us to determine the type of the path in one pass. Some other minor improvement added, like saving commonly used references instead of calculating them each time.
* Merge branch 'fix-out-of-bounds-markdown-refs' into 'master' Robert Speicher2016-06-181-1/+2
|\ | | | | | | | | | | | | | | | | Fix RangeError exceptions when referring to issues or merge requests outside of max database values When using #XYZ in Markdown text, if XYZ exceeds the maximum value of a signed 32-bit integer, we get an exception when the Markdown render attempts to run `where(iids: XYZ)`. Introduce a method that will throw out out-of-bounds values. Closes #18777 See merge request !4777
| * Fix RangeError exceptions when referring to issues or merge requests outside ↵Stan Hu2016-06-181-1/+2
| | | | | | | | | | | | | | | | | | | | of max database values When using #XYZ in Markdown text, if XYZ exceeds the maximum value of a signed 32-bit integer, we get an exception when the Markdown render attempts to run `where(iids: XYZ)`. Introduce a method that will throw out out-of-bounds values. Closes #18777
* | Fix bug in `WikiLinkFilter`.18819-wiki-link-filter-exceptionTimothy Andrew2016-06-181-1/+1
|/ | | | | | | 1. An exception would be raised if the filter was called with an invalid URI. Mainly because we weren't catching the `Addressable` exception. 2. This commit fixes it and adds a spec for the filter.
* Merge branch 'banzai-issue-filter-queries' into 'master' Douwe Maan2016-06-162-3/+79
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Reduce SQL query counts in IssueReferenceFilter ## What does this MR do? This MR adds a preparation phase for reference filters that allows them to prepare/create data structures used while iterating over HTML nodes. In this particular case the preparation phase is used for issue references to greatly cut down the amount of queries executed to get projects/issues for Markdown references. ## Are there points in the code the reviewer needs to double check? No. ## Why was this MR needed? Rendering Markdown containing issue references would run at most two queries for every issue reference: one to get the project and one to get the issue from said project. When rendering Markdown with lots of issue references this would result in _a lot_ of queries being executed. ## What are the relevant issue numbers? #18042 See merge request !4410
| * Reduce queries in IssueReferenceFilterbanzai-issue-filter-queriesYorick Peterse2016-06-162-3/+79
| | | | | | | | | | | | | | | | | | This reduces the number of queries executed in IssueReferenceFilter by retrieving the various projects/issues that may be referenced in batches _before_ iterating over all the HTML nodes. A chunk of the logic resides in AbstractReferenceFilter so it can be re-used by other filters in the future.
* | Banzai::Filter::ExternalLinkFilter use XPath18582-banzai-filter-external-link-filterPaco Guzman2016-06-161-11/+2
| |
* | Banzai::Filter::UploadLinkFilter use XPathPaco Guzman2016-06-161-8/+3
| |
* | Eager load project relations in IssueParserYorick Peterse2016-06-151-1/+15
|/ | | | | | | | | | | | | By eager loading these associations we can greatly cut down the number of SQL queries executed when processing documents with lots of references, especially in cases where there are references belonging to the same project. Since these associations are so specific to the reference parsing process and the permissions checking process that follows it I opted to include them directly in IssueParser instead of using something like a scope. Once we have a need for it we can move this code to a scope or method.
* 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.