2021-01-29 00:20:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
RSpec.describe Banzai::Pipeline::PreProcessPipeline, feature_category: :team_planning do
|
2021-01-29 00:20:46 +05:30
|
|
|
it 'pre-processes the source text' do
|
|
|
|
markdown = <<~MD
|
|
|
|
\xEF\xBB\xBF---
|
|
|
|
foo: :foo_symbol
|
|
|
|
bar: :bar_symbol
|
|
|
|
---
|
|
|
|
|
|
|
|
>>>
|
|
|
|
blockquote
|
|
|
|
>>>
|
|
|
|
MD
|
|
|
|
|
|
|
|
result = described_class.call(markdown, {})
|
|
|
|
|
|
|
|
aggregate_failures do
|
|
|
|
expect(result[:output]).not_to include "\xEF\xBB\xBF"
|
|
|
|
expect(result[:output]).not_to include '---'
|
2021-11-18 22:05:49 +05:30
|
|
|
expect(result[:output]).to include "```yaml:frontmatter\nfoo: :foo_symbol\n"
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(result[:output]).to include "> blockquote\n"
|
|
|
|
end
|
|
|
|
end
|
2021-03-08 18:12:59 +05:30
|
|
|
|
|
|
|
it 'truncates the text if requested' do
|
|
|
|
text = (['foo'] * 10).join(' ')
|
|
|
|
|
|
|
|
result = described_class.call(text, limit: 12)
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
expect(result[:output]).to eq('foo foo f...')
|
2021-03-08 18:12:59 +05:30
|
|
|
end
|
2022-10-11 01:57:18 +05:30
|
|
|
|
|
|
|
context 'when multiline blockquote' do
|
|
|
|
it 'data-sourcepos references correct line in source markdown' do
|
|
|
|
markdown = <<~MD
|
|
|
|
>>>
|
|
|
|
foo
|
|
|
|
>>>
|
|
|
|
MD
|
|
|
|
|
|
|
|
pipeline_output = described_class.call(markdown, {})[:output]
|
|
|
|
pipeline_output = Banzai::Pipeline::PlainMarkdownPipeline.call(pipeline_output, {})[:output]
|
|
|
|
sourcepos = pipeline_output.at('blockquote')['data-sourcepos']
|
|
|
|
source_line = sourcepos.split(':').first.to_i
|
|
|
|
|
|
|
|
expect(markdown.lines[source_line - 1]).to eq "foo\n"
|
|
|
|
end
|
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|