2017-01-16 15:27:05 -05:00
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
|
|
describe 'Copy as GFM', feature: true, js: true do
|
2017-04-03 05:55:15 -04:00
|
|
|
|
include MarkupHelper
|
2017-03-10 16:34:29 -05:00
|
|
|
|
include RepoHelpers
|
2017-01-16 15:27:05 -05:00
|
|
|
|
include ActionView::Helpers::JavaScriptHelper
|
|
|
|
|
|
|
|
|
|
before do
|
2017-06-21 19:44:10 -04:00
|
|
|
|
sign_in(create(:admin))
|
2017-03-10 16:34:29 -05:00
|
|
|
|
end
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
describe 'Copying rendered GFM' do
|
|
|
|
|
before do
|
|
|
|
|
@feat = MarkdownFeature.new
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
# `markdown` helper expects a `@project` variable
|
|
|
|
|
@project = @feat.project
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-07-06 12:20:50 -04:00
|
|
|
|
visit project_issue_path(@project, @feat.issue)
|
2017-03-10 16:34:29 -05:00
|
|
|
|
end
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
# The filters referenced in lib/banzai/pipeline/gfm_pipeline.rb convert GitLab Flavored Markdown (GFM) to HTML.
|
2017-03-15 19:31:01 -04:00
|
|
|
|
# The handlers defined in app/assets/javascripts/copy_as_gfm.js consequently convert that same HTML to GFM.
|
2017-03-10 16:34:29 -05:00
|
|
|
|
# To make sure these filters and handlers are properly aligned, this spec tests the GFM-to-HTML-to-GFM cycle
|
|
|
|
|
# by verifying (`html_to_gfm(gfm_to_html(gfm)) == gfm`) for a number of examples of GFM for every filter, using the `verify` helper.
|
2017-01-16 18:11:15 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
# These are all in a single `it` for performance reasons.
|
|
|
|
|
it 'works', :aggregate_failures do
|
|
|
|
|
verify(
|
|
|
|
|
'nesting',
|
2017-01-16 18:11:15 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
'> 1. [x] **[$`2 + 2`$ {-=-}{+=+} 2^2 ~~:thumbsup:~~](http://google.com)**'
|
|
|
|
|
)
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
verify(
|
|
|
|
|
'a real world example from the gitlab-ce README',
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
<<-GFM.strip_heredoc
|
|
|
|
|
# GitLab
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
[![Build status](https://gitlab.com/gitlab-org/gitlab-ce/badges/master/build.svg)](https://gitlab.com/gitlab-org/gitlab-ce/commits/master)
|
|
|
|
|
[![CE coverage report](https://gitlab.com/gitlab-org/gitlab-ce/badges/master/coverage.svg?job=coverage)](https://gitlab-org.gitlab.io/gitlab-ce/coverage-ruby)
|
|
|
|
|
[![Code Climate](https://codeclimate.com/github/gitlabhq/gitlabhq.svg)](https://codeclimate.com/github/gitlabhq/gitlabhq)
|
|
|
|
|
[![Core Infrastructure Initiative Best Practices](https://bestpractices.coreinfrastructure.org/projects/42/badge)](https://bestpractices.coreinfrastructure.org/projects/42)
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
## Canonical source
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
The canonical source of GitLab Community Edition is [hosted on GitLab.com](https://gitlab.com/gitlab-org/gitlab-ce/).
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
## Open source software to collaborate on code
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
To see how GitLab looks please see the [features page on our website](https://about.gitlab.com/features/).
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
- Manage Git repositories with fine grained access controls that keep your code secure
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
- Perform code reviews and enhance collaboration with merge requests
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
- Complete continuous integration (CI) and CD pipelines to builds, test, and deploy your applications
|
2017-01-24 17:55:12 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
- Each project can also have an issue tracker, issue board, and a wiki
|
2017-01-24 17:55:12 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
- Used by more than 100,000 organizations, GitLab is the most popular solution to manage Git repositories on-premises
|
2017-01-16 18:11:15 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
- Completely free and open source (MIT Expat license)
|
|
|
|
|
GFM
|
|
|
|
|
)
|
2017-01-24 17:55:12 -05:00
|
|
|
|
|
2017-05-23 15:56:05 -04:00
|
|
|
|
aggregate_failures('an accidentally selected empty element') do
|
|
|
|
|
gfm = '# Heading1'
|
|
|
|
|
|
|
|
|
|
html = <<-HTML.strip_heredoc
|
|
|
|
|
<h1>Heading1</h1>
|
|
|
|
|
|
|
|
|
|
<h2></h2>
|
|
|
|
|
HTML
|
|
|
|
|
|
2017-05-23 15:58:39 -04:00
|
|
|
|
output_gfm = html_to_gfm(html)
|
|
|
|
|
expect(output_gfm.strip).to eq(gfm.strip)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
aggregate_failures('an accidentally selected other element') do
|
|
|
|
|
gfm = 'Test comment with **Markdown!**'
|
|
|
|
|
|
|
|
|
|
html = <<-HTML.strip_heredoc
|
|
|
|
|
<li class="note">
|
|
|
|
|
<div class="md">
|
|
|
|
|
<p>
|
|
|
|
|
Test comment with <strong>Markdown!</strong>
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<li class="note"></li>
|
|
|
|
|
HTML
|
|
|
|
|
|
2017-05-23 15:56:05 -04:00
|
|
|
|
output_gfm = html_to_gfm(html)
|
|
|
|
|
expect(output_gfm.strip).to eq(gfm.strip)
|
|
|
|
|
end
|
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
verify(
|
|
|
|
|
'InlineDiffFilter',
|
2017-01-16 18:11:15 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
'{-Deleted text-}',
|
|
|
|
|
'{+Added text+}'
|
|
|
|
|
)
|
2017-01-24 17:55:12 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
verify(
|
|
|
|
|
'TaskListFilter',
|
2017-01-16 18:11:15 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
'- [ ] Unchecked task',
|
|
|
|
|
'- [x] Checked task',
|
|
|
|
|
'1. [ ] Unchecked numbered task',
|
|
|
|
|
'1. [x] Checked numbered task'
|
|
|
|
|
)
|
2017-01-24 17:55:12 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
verify(
|
|
|
|
|
'ReferenceFilter',
|
2017-01-16 18:11:15 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
# issue reference
|
|
|
|
|
@feat.issue.to_reference,
|
|
|
|
|
# full issue reference
|
|
|
|
|
@feat.issue.to_reference(full: true),
|
|
|
|
|
# issue URL
|
2017-07-06 12:20:50 -04:00
|
|
|
|
project_issue_url(@project, @feat.issue),
|
2017-03-10 16:34:29 -05:00
|
|
|
|
# issue URL with note anchor
|
2017-07-06 12:20:50 -04:00
|
|
|
|
project_issue_url(@project, @feat.issue, anchor: 'note_123'),
|
2017-03-10 16:34:29 -05:00
|
|
|
|
# issue link
|
2017-07-06 12:20:50 -04:00
|
|
|
|
"[Issue](#{project_issue_url(@project, @feat.issue)})",
|
2017-03-10 16:34:29 -05:00
|
|
|
|
# issue link with note anchor
|
2017-07-06 12:20:50 -04:00
|
|
|
|
"[Issue](#{project_issue_url(@project, @feat.issue, anchor: 'note_123')})"
|
2017-03-10 16:34:29 -05:00
|
|
|
|
)
|
2017-01-16 18:11:15 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
verify(
|
|
|
|
|
'AutolinkFilter',
|
2017-01-16 18:11:15 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
'https://example.com'
|
|
|
|
|
)
|
2017-01-16 18:11:15 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
verify(
|
|
|
|
|
'TableOfContentsFilter',
|
2017-01-16 18:11:15 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
'[[_TOC_]]'
|
|
|
|
|
)
|
2017-01-16 18:11:15 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
verify(
|
|
|
|
|
'EmojiFilter',
|
2017-01-24 17:55:12 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
':thumbsup:'
|
|
|
|
|
)
|
2017-01-24 17:55:12 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
verify(
|
|
|
|
|
'ImageLinkFilter',
|
|
|
|
|
|
|
|
|
|
'![Image](https://example.com/image.png)'
|
|
|
|
|
)
|
2017-01-24 17:55:12 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
verify(
|
|
|
|
|
'VideoLinkFilter',
|
2017-01-24 17:55:12 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
'![Video](https://example.com/video.mp4)'
|
|
|
|
|
)
|
2017-01-24 17:55:12 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
verify(
|
|
|
|
|
'MathFilter: math as converted from GFM to HTML',
|
2017-01-17 13:07:49 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
'$`c = \pm\sqrt{a^2 + b^2}`$',
|
2017-01-24 17:55:12 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
# math block
|
|
|
|
|
<<-GFM.strip_heredoc
|
|
|
|
|
```math
|
|
|
|
|
c = \pm\sqrt{a^2 + b^2}
|
|
|
|
|
```
|
|
|
|
|
GFM
|
|
|
|
|
)
|
2017-01-17 13:07:49 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
aggregate_failures('MathFilter: math as transformed from HTML to KaTeX') do
|
|
|
|
|
gfm = '$`c = \pm\sqrt{a^2 + b^2}`$'
|
|
|
|
|
|
|
|
|
|
html = <<-HTML.strip_heredoc
|
|
|
|
|
<span class="katex">
|
|
|
|
|
<span class="katex-mathml">
|
|
|
|
|
<math>
|
|
|
|
|
<semantics>
|
|
|
|
|
<mrow>
|
|
|
|
|
<mi>c</mi>
|
|
|
|
|
<mo>=</mo>
|
|
|
|
|
<mo>±</mo>
|
|
|
|
|
<msqrt>
|
|
|
|
|
<mrow>
|
|
|
|
|
<msup>
|
|
|
|
|
<mi>a</mi>
|
|
|
|
|
<mn>2</mn>
|
|
|
|
|
</msup>
|
|
|
|
|
<mo>+</mo>
|
|
|
|
|
<msup>
|
|
|
|
|
<mi>b</mi>
|
|
|
|
|
<mn>2</mn>
|
|
|
|
|
</msup>
|
|
|
|
|
</mrow>
|
|
|
|
|
</msqrt>
|
|
|
|
|
</mrow>
|
|
|
|
|
<annotation encoding="application/x-tex">c = \\pm\\sqrt{a^2 + b^2}</annotation>
|
|
|
|
|
</semantics>
|
|
|
|
|
</math>
|
|
|
|
|
</span>
|
|
|
|
|
<span class="katex-html" aria-hidden="true">
|
|
|
|
|
<span class="strut" style="height: 0.913389em;"></span>
|
|
|
|
|
<span class="strut bottom" style="height: 1.04em; vertical-align: -0.126611em;"></span>
|
|
|
|
|
<span class="base textstyle uncramped">
|
|
|
|
|
<span class="mord mathit">c</span>
|
|
|
|
|
<span class="mrel">=</span>
|
|
|
|
|
<span class="mord">±</span>
|
|
|
|
|
<span class="sqrt mord"><span class="sqrt-sign" style="top: -0.073389em;">
|
|
|
|
|
<span class="style-wrap reset-textstyle textstyle uncramped">√</span>
|
|
|
|
|
</span>
|
|
|
|
|
<span class="vlist">
|
|
|
|
|
<span class="" style="top: 0em;">
|
|
|
|
|
<span class="fontsize-ensurer reset-size5 size5">
|
|
|
|
|
<span class="" style="font-size: 1em;"></span>
|
|
|
|
|
</span>
|
|
|
|
|
<span class="mord textstyle cramped">
|
|
|
|
|
<span class="mord">
|
|
|
|
|
<span class="mord mathit">a</span>
|
|
|
|
|
<span class="msupsub">
|
|
|
|
|
<span class="vlist">
|
|
|
|
|
<span class="" style="top: -0.289em; margin-right: 0.05em;">
|
|
|
|
|
<span class="fontsize-ensurer reset-size5 size5">
|
|
|
|
|
<span class="" style="font-size: 0em;"></span>
|
|
|
|
|
</span>
|
|
|
|
|
<span class="reset-textstyle scriptstyle cramped">
|
|
|
|
|
<span class="mord mathrm">2</span>
|
|
|
|
|
</span>
|
2017-01-17 13:07:49 -05:00
|
|
|
|
</span>
|
2017-03-10 16:34:29 -05:00
|
|
|
|
<span class="baseline-fix">
|
|
|
|
|
<span class="fontsize-ensurer reset-size5 size5">
|
|
|
|
|
<span class="" style="font-size: 0em;"></span>
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
2017-01-17 13:07:49 -05:00
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
2017-03-10 16:34:29 -05:00
|
|
|
|
<span class="mbin">+</span>
|
|
|
|
|
<span class="mord">
|
|
|
|
|
<span class="mord mathit">b</span>
|
|
|
|
|
<span class="msupsub">
|
|
|
|
|
<span class="vlist">
|
|
|
|
|
<span class="" style="top: -0.289em; margin-right: 0.05em;">
|
|
|
|
|
<span class="fontsize-ensurer reset-size5 size5">
|
|
|
|
|
<span class="" style="font-size: 0em;"></span>
|
|
|
|
|
</span>
|
|
|
|
|
<span class="reset-textstyle scriptstyle cramped">
|
|
|
|
|
<span class="mord mathrm">2</span>
|
|
|
|
|
</span>
|
2017-01-17 13:07:49 -05:00
|
|
|
|
</span>
|
2017-03-10 16:34:29 -05:00
|
|
|
|
<span class="baseline-fix">
|
|
|
|
|
<span class="fontsize-ensurer reset-size5 size5">
|
|
|
|
|
<span class="" style="font-size: 0em;"></span>
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
2017-01-17 13:07:49 -05:00
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
2017-03-10 16:34:29 -05:00
|
|
|
|
<span class="" style="top: -0.833389em;">
|
|
|
|
|
<span class="fontsize-ensurer reset-size5 size5">
|
|
|
|
|
<span class="" style="font-size: 1em;"></span>
|
|
|
|
|
</span>
|
|
|
|
|
<span class="reset-textstyle textstyle uncramped sqrt-line"></span>
|
2017-01-17 13:07:49 -05:00
|
|
|
|
</span>
|
2017-03-10 16:34:29 -05:00
|
|
|
|
<span class="baseline-fix">
|
|
|
|
|
<span class="fontsize-ensurer reset-size5 size5">
|
|
|
|
|
<span class="" style="font-size: 1em;"></span>
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
2017-01-17 13:07:49 -05:00
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
|
|
|
|
</span>
|
2017-03-10 16:34:29 -05:00
|
|
|
|
HTML
|
2017-01-17 13:07:49 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
output_gfm = html_to_gfm(html)
|
|
|
|
|
expect(output_gfm.strip).to eq(gfm.strip)
|
|
|
|
|
end
|
2017-01-17 13:07:49 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
verify(
|
|
|
|
|
'SanitizationFilter',
|
2017-01-24 17:55:12 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
<<-GFM.strip_heredoc
|
|
|
|
|
<a name="named-anchor"></a>
|
2017-02-27 23:44:34 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
<sub>sub</sub>
|
2017-01-19 11:01:27 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
<dl>
|
|
|
|
|
<dt>dt</dt>
|
|
|
|
|
<dd>dd</dd>
|
|
|
|
|
</dl>
|
2017-01-19 11:01:27 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
<kbd>kbd</kbd>
|
2017-01-19 11:01:27 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
<q>q</q>
|
2017-01-19 11:01:27 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
<samp>samp</samp>
|
2017-01-19 11:01:27 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
<var>var</var>
|
2017-01-19 11:01:27 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
<ruby>ruby</ruby>
|
2017-01-19 11:01:27 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
<rt>rt</rt>
|
2017-01-19 11:01:27 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
<rp>rp</rp>
|
2017-01-19 11:01:27 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
<abbr>abbr</abbr>
|
2016-09-28 07:46:11 -04:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
<summary>summary</summary>
|
2016-09-28 07:46:11 -04:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
<details>details</details>
|
|
|
|
|
GFM
|
|
|
|
|
)
|
2017-01-19 11:01:27 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
verify(
|
|
|
|
|
'SanitizationFilter',
|
2017-01-24 17:55:12 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
<<-GFM.strip_heredoc,
|
|
|
|
|
```
|
|
|
|
|
Plain text
|
|
|
|
|
```
|
|
|
|
|
GFM
|
2017-01-17 13:07:49 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
<<-GFM.strip_heredoc,
|
|
|
|
|
```ruby
|
|
|
|
|
def foo
|
|
|
|
|
bar
|
|
|
|
|
end
|
|
|
|
|
```
|
|
|
|
|
GFM
|
|
|
|
|
|
|
|
|
|
<<-GFM.strip_heredoc
|
|
|
|
|
Foo
|
|
|
|
|
|
|
|
|
|
This is an example of GFM
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
Code goes here
|
|
|
|
|
```
|
|
|
|
|
GFM
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
verify(
|
|
|
|
|
'MarkdownFilter',
|
|
|
|
|
|
|
|
|
|
"Line with two spaces at the end \nto insert a linebreak",
|
|
|
|
|
|
|
|
|
|
'`code`',
|
|
|
|
|
'`` code with ` ticks ``',
|
|
|
|
|
|
|
|
|
|
'> Quote',
|
|
|
|
|
|
|
|
|
|
# multiline quote
|
|
|
|
|
<<-GFM.strip_heredoc,
|
|
|
|
|
> Multiline
|
|
|
|
|
> Quote
|
|
|
|
|
>
|
|
|
|
|
> With multiple paragraphs
|
|
|
|
|
GFM
|
|
|
|
|
|
|
|
|
|
'![Image](https://example.com/image.png)',
|
|
|
|
|
|
|
|
|
|
'# Heading with no anchor link',
|
|
|
|
|
|
|
|
|
|
'[Link](https://example.com)',
|
|
|
|
|
|
|
|
|
|
'- List item',
|
|
|
|
|
|
|
|
|
|
# multiline list item
|
|
|
|
|
<<-GFM.strip_heredoc,
|
|
|
|
|
- Multiline
|
|
|
|
|
List item
|
|
|
|
|
GFM
|
|
|
|
|
|
|
|
|
|
# nested lists
|
|
|
|
|
<<-GFM.strip_heredoc,
|
|
|
|
|
- Nested
|
|
|
|
|
|
|
|
|
|
- Lists
|
|
|
|
|
GFM
|
|
|
|
|
|
|
|
|
|
# list with blockquote
|
|
|
|
|
<<-GFM.strip_heredoc,
|
|
|
|
|
- List
|
|
|
|
|
|
|
|
|
|
> Blockquote
|
|
|
|
|
GFM
|
|
|
|
|
|
|
|
|
|
'1. Numbered list item',
|
|
|
|
|
|
|
|
|
|
# multiline numbered list item
|
|
|
|
|
<<-GFM.strip_heredoc,
|
|
|
|
|
1. Multiline
|
|
|
|
|
Numbered list item
|
|
|
|
|
GFM
|
|
|
|
|
|
|
|
|
|
# nested numbered list
|
|
|
|
|
<<-GFM.strip_heredoc,
|
|
|
|
|
1. Nested
|
2017-01-19 14:54:59 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
1. Numbered lists
|
|
|
|
|
GFM
|
2017-01-19 14:54:59 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
'# Heading',
|
|
|
|
|
'## Heading',
|
|
|
|
|
'### Heading',
|
|
|
|
|
'#### Heading',
|
|
|
|
|
'##### Heading',
|
|
|
|
|
'###### Heading',
|
2017-01-16 18:11:15 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
'**Bold**',
|
2017-01-24 17:55:12 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
'_Italics_',
|
2017-01-19 14:47:54 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
'~~Strikethrough~~',
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
'2^2',
|
2017-01-17 13:07:49 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
'-----',
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
# table
|
|
|
|
|
<<-GFM.strip_heredoc,
|
|
|
|
|
| Centered | Right | Left |
|
|
|
|
|
|:--------:|------:|------|
|
|
|
|
|
| Foo | Bar | **Baz** |
|
|
|
|
|
| Foo | Bar | **Baz** |
|
|
|
|
|
GFM
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
# table with empty heading
|
|
|
|
|
<<-GFM.strip_heredoc,
|
|
|
|
|
| | x | y |
|
|
|
|
|
|---|---|---|
|
|
|
|
|
| a | 1 | 0 |
|
|
|
|
|
| b | 0 | 1 |
|
|
|
|
|
GFM
|
|
|
|
|
)
|
|
|
|
|
end
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
alias_method :gfm_to_html, :markdown
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
def verify(label, *gfms)
|
|
|
|
|
aggregate_failures(label) do
|
|
|
|
|
gfms.each do |gfm|
|
|
|
|
|
html = gfm_to_html(gfm)
|
|
|
|
|
output_gfm = html_to_gfm(html)
|
|
|
|
|
expect(output_gfm.strip).to eq(gfm.strip)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-01-16 18:11:15 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
# Fake a `current_user` helper
|
|
|
|
|
def current_user
|
|
|
|
|
@feat.user
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-01-16 18:11:15 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
describe 'Copying code' do
|
2017-03-28 17:13:16 -04:00
|
|
|
|
let(:project) { create(:project, :repository) }
|
2017-01-16 18:11:15 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
context 'from a diff' do
|
|
|
|
|
before do
|
2017-07-06 12:20:50 -04:00
|
|
|
|
visit project_commit_path(project, sample_commit.id)
|
2017-03-10 16:34:29 -05:00
|
|
|
|
end
|
2017-01-16 18:11:15 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
context 'selecting one word of text' do
|
|
|
|
|
it 'copies as inline code' do
|
|
|
|
|
verify(
|
|
|
|
|
'[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"] .line .no',
|
2017-01-19 14:47:54 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
'`RuntimeError`'
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-01-19 14:47:54 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
context 'selecting one line of text' do
|
|
|
|
|
it 'copies as inline code' do
|
|
|
|
|
verify(
|
|
|
|
|
'[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"] .line',
|
2017-01-16 18:11:15 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
'`raise RuntimeError, "System commands must be given as an array of strings"`'
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-01-16 18:11:15 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
context 'selecting multiple lines of text' do
|
|
|
|
|
it 'copies as a code block' do
|
|
|
|
|
verify(
|
|
|
|
|
'[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"], [id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_10"]',
|
|
|
|
|
|
|
|
|
|
<<-GFM.strip_heredoc,
|
|
|
|
|
```ruby
|
|
|
|
|
raise RuntimeError, "System commands must be given as an array of strings"
|
|
|
|
|
end
|
|
|
|
|
```
|
|
|
|
|
GFM
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'from a blob' do
|
|
|
|
|
before do
|
2017-07-06 12:20:50 -04:00
|
|
|
|
visit project_blob_path(project, File.join('master', 'files/ruby/popen.rb'))
|
2017-05-17 14:25:13 -04:00
|
|
|
|
wait_for_requests
|
2017-03-10 16:34:29 -05:00
|
|
|
|
end
|
2017-01-16 18:11:15 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
context 'selecting one word of text' do
|
|
|
|
|
it 'copies as inline code' do
|
|
|
|
|
verify(
|
|
|
|
|
'.line[id="LC9"] .no',
|
2017-01-16 18:11:15 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
'`RuntimeError`'
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-01-16 18:11:15 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
context 'selecting one line of text' do
|
|
|
|
|
it 'copies as inline code' do
|
|
|
|
|
verify(
|
|
|
|
|
'.line[id="LC9"]',
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
'`raise RuntimeError, "System commands must be given as an array of strings"`'
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'selecting multiple lines of text' do
|
|
|
|
|
it 'copies as a code block' do
|
|
|
|
|
verify(
|
|
|
|
|
'.line[id="LC9"], .line[id="LC10"]',
|
|
|
|
|
|
|
|
|
|
<<-GFM.strip_heredoc,
|
|
|
|
|
```ruby
|
|
|
|
|
raise RuntimeError, "System commands must be given as an array of strings"
|
|
|
|
|
end
|
|
|
|
|
```
|
|
|
|
|
GFM
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
context 'from a GFM code block' do
|
|
|
|
|
before do
|
2017-07-06 12:20:50 -04:00
|
|
|
|
visit project_blob_path(project, File.join('markdown', 'doc/api/users.md'))
|
2017-05-17 14:25:13 -04:00
|
|
|
|
wait_for_requests
|
2017-03-10 16:34:29 -05:00
|
|
|
|
end
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
context 'selecting one word of text' do
|
|
|
|
|
it 'copies as inline code' do
|
|
|
|
|
verify(
|
|
|
|
|
'.line[id="LC27"] .s2',
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
'`"bio"`'
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
context 'selecting one line of text' do
|
|
|
|
|
it 'copies as inline code' do
|
|
|
|
|
verify(
|
|
|
|
|
'.line[id="LC27"]',
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
'`"bio": null,`'
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-01-16 15:27:05 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
context 'selecting multiple lines of text' do
|
2017-03-13 14:17:07 -04:00
|
|
|
|
it 'copies as a code block with the correct language' do
|
2017-03-10 16:34:29 -05:00
|
|
|
|
verify(
|
|
|
|
|
'.line[id="LC27"], .line[id="LC28"]',
|
|
|
|
|
|
|
|
|
|
<<-GFM.strip_heredoc,
|
|
|
|
|
```json
|
|
|
|
|
"bio": null,
|
|
|
|
|
"skype": "",
|
|
|
|
|
```
|
|
|
|
|
GFM
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-01-19 14:47:54 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
def verify(selector, gfm)
|
|
|
|
|
html = html_for_selector(selector)
|
2017-03-13 18:39:22 -04:00
|
|
|
|
output_gfm = html_to_gfm(html, 'transformCodeSelection')
|
2017-03-10 16:34:29 -05:00
|
|
|
|
expect(output_gfm.strip).to eq(gfm.strip)
|
|
|
|
|
end
|
2017-01-16 15:27:05 -05:00
|
|
|
|
end
|
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
def html_for_selector(selector)
|
|
|
|
|
js = <<-JS.strip_heredoc
|
|
|
|
|
(function(selector) {
|
|
|
|
|
var els = document.querySelectorAll(selector);
|
|
|
|
|
var htmls = _.map(els, function(el) { return el.outerHTML; });
|
|
|
|
|
return htmls.join("\\n");
|
|
|
|
|
})("#{escape_javascript(selector)}")
|
|
|
|
|
JS
|
|
|
|
|
page.evaluate_script(js)
|
|
|
|
|
end
|
2017-01-16 18:11:15 -05:00
|
|
|
|
|
2017-03-10 16:34:29 -05:00
|
|
|
|
def html_to_gfm(html, transformer = 'transformGFMSelection')
|
2017-01-16 15:27:05 -05:00
|
|
|
|
js = <<-JS.strip_heredoc
|
|
|
|
|
(function(html) {
|
2017-03-14 17:27:05 -04:00
|
|
|
|
var transformer = window.gl.CopyAsGFM[#{transformer.inspect}];
|
|
|
|
|
|
2017-01-16 15:27:05 -05:00
|
|
|
|
var node = document.createElement('div');
|
|
|
|
|
node.innerHTML = html;
|
2017-03-14 17:27:05 -04:00
|
|
|
|
|
|
|
|
|
node = transformer(node);
|
|
|
|
|
if (!node) return null;
|
|
|
|
|
|
|
|
|
|
return window.gl.CopyAsGFM.nodeToGFM(node);
|
2017-01-16 15:27:05 -05:00
|
|
|
|
})("#{escape_javascript(html)}")
|
|
|
|
|
JS
|
|
|
|
|
page.evaluate_script(js)
|
|
|
|
|
end
|
|
|
|
|
end
|