summaryrefslogtreecommitdiff
path: root/lib/banzai
Commit message (Collapse)AuthorAgeFilesLines
* Enable Style/EmptyLinesAroundClassBody coprubocop/EmptyLinesAroundModuleBodyGabriel Mazetto2016-08-061-1/+0
|
* Enable Style/EmptyLinesAroundModuleBody copGabriel Mazetto2016-08-061-2/+0
|
* Ignore URLs starting with // (!5677)winniehell2016-08-051-1/+2
|
* Merge branch 'syntax-highlight-filter-performance' into 'master' Rémy Coutable2016-08-041-8/+18
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Improve performance of SyntaxHighlightFilter ## What does this MR do? This MR improves the performance of `Banzai::Filter::SyntaxHighlightFilter`. See e9bacc6575d0002c6cab620075dea3dc7f93f100 for more information. ## Are there points in the code the reviewer needs to double check? Styling mostly. ## Why was this MR needed? Syntax highlighting is rather slow. ## What are the relevant issue numbers? #18592 ## Does this MR meet the acceptance criteria? - [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added - [x] ~~[Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)~~ - [x] ~~API support added~~ - Tests - [x] ~~Added for this feature/bug~~ - [ ] All builds are passing - [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides) - [ ] Branch has no merge conflicts with `master` (if you do - rebase it please) - [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits) See merge request !5643
| * Improve performance of SyntaxHighlightFiltersyntax-highlight-filter-performanceYorick Peterse2016-08-031-8/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | By using Rouge::Lexer.find instead of find_fancy() and memoizing the HTML formatter we can speed up the highlighting process by between 1.7 and 1.8 times (at least when measured using synthetic benchmarks). To measure this I used the following benchmark: require 'benchmark/ips' input = '' Dir['./app/controllers/**/*.rb'].each do |controller| input << <<-EOF <pre><code class="ruby">#{File.read(controller).strip}</code></pre> EOF end document = Nokogiri::HTML.fragment(input) filter = Banzai::Filter::SyntaxHighlightFilter.new(document) puts "Input size: #{(input.bytesize.to_f / 1024).round(2)} KB" Benchmark.ips do |bench| bench.report 'call' do filter.call end end This benchmark produces 250 KB of input. Before these changes the timing output would be as follows: Calculating ------------------------------------- call 1.000 i/100ms ------------------------------------------------- call 22.439 (±35.7%) i/s - 93.000 After these changes the output instead is as follows: Calculating ------------------------------------- call 1.000 i/100ms ------------------------------------------------- call 41.283 (±38.8%) i/s - 148.000 Note that due to the fairly high standard deviation and this being a synthetic benchmark it's entirely possible the real-world improvements are smaller.
* | Improve AutolinkFilter#text_parse performanceautolink-filter-text-parseYorick Peterse2016-08-031-6/+9
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | By using clever XPath queries we can quite significantly improve the performance of this method. The actual improvement depends a bit on the amount of links used but in my tests the new implementation is usually around 8 times faster than the old one. This was measured using the following benchmark: require 'benchmark/ips' text = '<p>' + Note.select("string_agg(note, '') AS note").limit(50).take[:note] + '</p>' document = Nokogiri::HTML.fragment(text) filter = Banzai::Filter::AutolinkFilter.new(document, autolink: true) puts "Input size: #{(text.bytesize.to_f / 1024 / 1024).round(2)} MB" filter.rinku_parse Benchmark.ips(time: 15) do |bench| bench.report 'text_parse' do filter.text_parse end bench.report 'text_parse_fast' do filter.text_parse_fast end bench.compare! end Here the "text_parse_fast" method is the new implementation and "text_parse" the old one. The input size was around 180 MB. Running this benchmark outputs the following: Input size: 181.16 MB Calculating ------------------------------------- text_parse 1.000 i/100ms text_parse_fast 9.000 i/100ms ------------------------------------------------- text_parse 13.021 (±15.4%) i/s - 188.000 text_parse_fast 112.741 (± 3.5%) i/s - 1.692k Comparison: text_parse_fast: 112.7 i/s text_parse: 13.0 i/s - 8.66x slower Again the production timings may (and most likely will) vary depending on the input being processed.
* Add support for relative links starting with ./ or / to RelativeLinkFilter ↵winniehell2016-08-021-0/+3
| | | | (!5586)
* Merge branch 'ability-batch-issue-checking' into 'master' Robert Speicher2016-07-291-3/+4
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Optimize checking if a user can read multiple issues ## What does this MR do? This optimizes various parts of the code so it can more efficiently check if a user can read a list of issues. ## Are there points in the code the reviewer needs to double check? Yes, in particular `Ability.issues_readable_by_user` should be checked to make sure it correctly allows/restricts access to issues. ## Why was this MR needed? Currently the general approach to checking if one can read an issue is to iterate over the issues to check and call `can?(user, :read_issue, issue)` for every issue. This is not efficient as the same work has to be done for every issue. ## What are the relevant issue numbers? * #15607 * #17463 See merge request !5370
| * Method for returning issues readable by a userability-batch-issue-checkingYorick Peterse2016-07-291-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | The method Ability.issues_readable_by_user takes a list of users and an optional user and returns an Array of issues readable by said user. This method in turn is used by Banzai::ReferenceParser::IssueParser#nodes_visible_to_user so this method no longer needs to get all the available abilities just to check if a user has the "read_issue" ability. To test this I benchmarked an issue with 222 comments on my development environment. Using these changes the time spent in nodes_visible_to_user was reduced from around 120 ms to around 40 ms.
* | Merge branch 'rubocop/enable-access-modifiers-cops' into 'master' Robert Speicher2016-07-293-19/+21
|\ \ | |/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Enable Rubocop cops that check access modifiers ## What does this MR do? This MR enables Rubocop cops that detect methods that should be restricted but are the part of public API because of access modifiers used improperly. This also fixes existing offenses. ## Why was this MR needed? Some method in our codebase are public instead of being private because it is sometimes difficult to get it right without static analysis. ## What are the relevant issue numbers? See #17478 Closes #17372 See merge request !5014
| * Fix method visiblity in emoji filter classGrzegorz Bizon2016-07-191-5/+5
| |
| * Fix methods visibility in markdown filter classGrzegorz Bizon2016-07-191-7/+7
| |
| * Make banzai module that handles markdown singletonGrzegorz Bizon2016-07-191-7/+9
| |
* | Ensure relative paths for video are rewritten as we do for images20189-markdown-video-doesn-t-work-when-the-referenced-video-file-is-in-same-repoRémy Coutable2016-07-261-1/+1
| | | | | | | | Signed-off-by: Rémy Coutable <remy@rymai.me>
* | Retrieve rendered HTML from cache in one requestfix/get-cached-rendered-html-using-single-redis-requestAhmad Sherif2016-07-211-4/+5
| | | | | | | | See #19985
* | Merge branch '4142-show-inline-video' into 'master' Rémy Coutable2016-07-212-0/+60
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add support for inline videos in issue, MR and notes (on issue, commit, MR, and MR diff) ## What does this MR do? It adds support for inline videos in issue, MR and notes (on issue, commit, MR, and MR diff). Most of the work was done by @hayesr in !3508 but a few improvements were still missing. ## Why was this MR needed? To be able to play uploaded videos in GitLab! ## What are the relevant issue numbers? Closes #4142. ## Screenshots ### Video players ![Screen_Shot_2016-07-19_at_18.44.09](/uploads/e85e531b455a41c3e66b26b356abaafd/Screen_Shot_2016-07-19_at_18.44.09.png) ----- ![Screen_Shot_2016-07-19_at_18.44.29](/uploads/05f52a812760210d1eae86a7f8fc48bc/Screen_Shot_2016-07-19_at_18.44.29.png) ----- ## Does this MR meet the acceptance criteria? - [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added - [x] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md) - Tests - [x] Test `VideoLinkFilter` - [x] Test in `spec/features/markdown_spec.rb` - [x] Improve `spec/uploaders/file_uploader_spec.rb` - [x] All builds are passing - [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides) - [x] Branch has no merge conflicts with `master` (if you do - rebase it please) - [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits) See merge request !5215
| * | Remove VideoJS and clean the integrationRémy Coutable2016-07-201-9/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | Handle videos in: - MD preview in notes: commit, issue/MR, MR diff - New notes in: commit, issue/MR, MR diff - Persisted notes in: commit, issue/MR, MR diff Signed-off-by: Rémy Coutable <remy@rymai.me>
| * | Use a more powerful query to match videos in img tagsRémy Coutable2016-07-192-10/+35
| | | | | | | | | | | | | | | | | | | | | | | | Also, always add a link to download videos since video playback is tricky. Also, it solves the issue with email client not supporting videos. Signed-off-by: Rémy Coutable <remy@rymai.me>
| * | Remove duplication, useless rescue, and avoid using ActionViewRémy Coutable2016-07-191-14/+9
| | | | | | | | | | | | Signed-off-by: Rémy Coutable <remy@rymai.me>
| * | First support of videos in issues, MRs and notesEric Hayes2016-07-192-0/+43
| |/ | | | | | | | | * Registered video MIME types * Currently supporting browser-supported formats with extensions that match the mime type
* | Enable Style/MultilineTernaryOperator rubocop coprubocop/enable-multiline-ternary-operator-copGrzegorz Bizon2016-07-201-2/+1
|/ | | | | | Avoid multi-line ?: (the ternary operator). Use if/unless instead. See #17478
* Don't parse Rinku returned value to DocFragment when it didn't change the ↵18593-avoid-parse_html-when-rinku-didnt-do-anythingPaco Guzman2016-07-181-0/+2
| | | | original html string.
* Merge branch 'syntax-highlight-unknown-language' into 'master' Robert Speicher2016-07-161-7/+8
|\ | | | | | | | | | | | | Don't fail to highlight when Rouge doesn't have a lexer Fixes issue introduced by upgrade to Rouge 2.0 (https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/4691) See merge request !5291
| * Don't fail to highlight when Rouge doesn't have a lexerDouwe Maan2016-07-151-7/+8
| |
* | Merge branch 'mentioned-user-tooltip' into 'master' Douwe Maan2016-07-151-5/+5
|\ \ | |/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Display tooltip for mentioned users and groups ## What does this MR do? Display tooltip for mentioned users and groups in Markdown. ## Are there points in the code the reviewer needs to double check? I don't know. ## Why was this MR needed? No tooltips were displayed. ## What are the relevant issue numbers? fixes #17060 ## Screenshots ![user-tooltip](/uploads/501b7d1b2a5e6adcadefbc56b08422ec/user-tooltip.png) ![group-tooltip](/uploads/0152a452f9a1ed9fc86101b242f7e4c2/group-tooltip.png) See merge request !5261
| * Display tooltip for mentioned users and groups (!5261)winniehell2016-07-141-5/+5
| |
* | use %(...) and %[...] in favor of %<...>feature.rouge-20http://jneen.net/2016-07-141-2/+2
| |
* | bugfix: don't error in css_classeshttp://jneen.net/2016-07-141-5/+8
| |
* | without line anchors, this is just the plain HTML formatterhttp://jneen.net/2016-07-141-1/+1
| |
* | kill the :cssclass optionhttp://jneen.net/2016-07-141-2/+1
| |
* | add the wrapping back in for the banzai filterhttp://jneen.net/2016-07-141-1/+5
|/
* ObjectRenderer doesn't crash when no objects to cache with ↵Paco Guzman2016-07-131-4/+10
| | | | Rails.cache.read_multi
* Object renderer read_multi rendered entries from Cacheread-multi-rendered-objectsPaco Guzman2016-07-122-11/+68
|
* Optimize system note visibility checking by hiding notes thatStan Hu2016-07-112-18/+29
| | | | | | | | | | | | | have been fully redacted and contain cross-project references. The previous implementation relied on Note#cross_reference_not_visible_for?, which essentially tries to render all the Markdown references in a system note and only displays the note if the user can see the referring project. But this duplicated the work that Banzai::NotesRenderer was doing already. Instead, for each note we render, we memoize the number of visible user references and use it later if it is available. Improves #19273
* Merge branch 'blockquote-fence-filter' into 'master' Robert Speicher2016-07-102-1/+73
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add blockquote fence syntax to Markdown Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/16564 Before Markdown rendering happens, this will transform this: ``` Let me quote this here email: >>> Dear friend, How are you? Greetings, Me >>> ``` Into this, saving me from having to prefix all of those lines with `>` manually when I copy some multiline text from another medium: ``` Let me quote this here email: > Dear friend, > > How are you? > > Greetings, > > Me ``` See merge request !3954
| * Add more comments to regexDouwe Maan2016-07-101-11/+32
| |
| * Add blockquote fence syntax to MarkdownDouwe Maan2016-07-092-1/+52
| |
* | Re-use queries in reference parsersreuse-queries-in-reference-parsersYorick Peterse2016-07-082-4/+37
|/ | | | | This caches various queries to ensure that multiple reference extraction runs re-use any objects queried in previous runs.
* Use CGI.unescapeHTML rather than doing the gsub with a mapDouglas Barbosa Alexandre2016-07-051-1/+1
|
* Move `unescape_html_entities` from LabelsHelper to Label modelDouglas Barbosa Alexandre2016-07-051-1/+1
|
* Render references for labels that name contains ?, or &Douglas Barbosa Alexandre2016-07-051-2/+6
|
* Merge branch 'update-gemoji' into 'master' Robert Speicher2016-07-051-2/+2
|\ | | | | | | | | | | | | | | | | | | | | Add lib/gitlab/emoji.rb instead of gitlab_emoji gem and upgrade Gemojione - No reason to split it into a separate gem when the gem barely did anything. We can use gemojione directly, making updating gemojione that much easier. Unless there's a particularly good reason we were using the gem? - Fixes the Rake task since it broke after all the AwardEmoji changes. - Update gemojione to 2.6.1. Spring Update changes! http://emojione.com/releases/#2.2.0 See merge request !4919
| * Add emoji.rb in lib/gitlab instead of using the gitlab_emoji gem.update-gemojiConnor Shea2016-06-291-2/+2
| | | | | | | | | | | | | | | | No reason to split it into a separate gem when the gem barely did anything. We can use gemojione directly, making updating gemojione that much easier. Also fix the Rake task and update gemojione to 2.6.1. This adds the EmojiOne Spring update. Changelog: https://github.com/jonathanwiesel/gemojione/blob/master/CHANGELOG.md
* | Enable Style/EmptyLines cop, remove redundant onesrubocop/enable-cops-for-empty-linesGrzegorz Bizon2016-07-013-3/+0
| |
* | Metrics for Rouge::Plugins::Redcarpet and Rouge::Formatters::HTMLGitlab18592-syntaxhighlighter-slowPaco Guzman2016-07-011-2/+7
| |
* | Handle external issues in IssueReferenceFilterYorick Peterse2016-06-303-6/+30
|/ | | | | | | | | | | IssueReferenceFilter will end up processing internal issue references when a project uses an external issues tracker while still using internal issue references (in the form of `#\d+`). This commit ensures that these links are rendered as external issue links, regardless of whether the project one currently views uses an internal or external issues tracker. Fixes gitlab-org/gitlab-ce#19036, gitlab-com/performance#16
* 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