Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change role of pagination layer to pseudo layer on advanced background #27

Merged
merged 2 commits into from
May 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Add `header` and `footer` directives ([#22](https://github.com/marp-team/marpit/pull/22))
* Support importing other theme CSS with `@import` (or `@import-theme`) ([#24](https://github.com/marp-team/marpit/pull/24))
* Add PostCSS import rollup plugin to work `@charset` and `@import` at-rules correctly ([#26](https://github.com/marp-team/marpit/pull/26))
* Change role of pagination layer to pseudo layer on advanced background ([#27](https://github.com/marp-team/marpit/pull/27))

## v0.0.5 - 2018-05-12

Expand Down
44 changes: 21 additions & 23 deletions src/markdown/background_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,29 +189,27 @@ function backgroundImage(md) {
t,
]
} else if (current && t.type === 'marpit_inline_svg_content_close') {
const { open } = current.meta.marpitBackground
const marpitPagination = open.attrGet('data-marpit-pagination')

if (marpitPagination) {
const { height, width } = current.meta.marpitBackground
tokens = [
t,
...wrapTokens(
'marpit_advanced_background_foreign_object',
{
tag: 'foreignObject',
width,
height,
'data-marpit-advanced-background': 'pagination',
},
wrapTokens('marpit_advanced_pagination_section', {
tag: 'section',
'data-marpit-advanced-background': 'pagination',
'data-marpit-pagination': marpitPagination,
})
),
]
}
const { open, height, width } = current.meta.marpitBackground

tokens = [
t,
...wrapTokens(
'marpit_advanced_background_foreign_object',
{
tag: 'foreignObject',
width,
height,
'data-marpit-advanced-background': 'pseudo',
},
wrapTokens('marpit_advanced_pseudo_section', {
tag: 'section',
'data-marpit-advanced-background': 'pseudo',
'data-marpit-pagination': open.attrGet(
'data-marpit-pagination'
),
})
),
]

current = undefined
}
Expand Down
8 changes: 5 additions & 3 deletions src/postcss/advanced_background.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ section[data-marpit-advanced-background="background"] {
padding: 0 !important;
}

section[data-marpit-advanced-background="background"]::before,
section[data-marpit-advanced-background="background"]::after,
section[data-marpit-advanced-background="content"]::before,
section[data-marpit-advanced-background="content"]::after {
display: none !important;
}
Expand Down Expand Up @@ -49,12 +51,12 @@ section[data-marpit-advanced-background="background"] > div[data-marpit-advanced
}

section[data-marpit-advanced-background="content"],
section[data-marpit-advanced-background="pagination"] {
section[data-marpit-advanced-background="pseudo"] {
background: transparent !important;
}

section[data-marpit-advanced-background="pagination"],
:marpit-container > svg > foreignObject[data-marpit-advanced-background="pagination"] {
section[data-marpit-advanced-background="pseudo"],
:marpit-container > svg > foreignObject[data-marpit-advanced-background="pseudo"] {
pointer-events: none !important;
}

Expand Down
44 changes: 24 additions & 20 deletions test/markdown/background_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ describe('Marpit background image plugin', () => {
lowerCaseTags: false,
})

it('renders the structure for advanced background to another foreignObject', () => {
it('renders advanced background to another foreignObject', () => {
const $ = $load(mdSVG().render('![bg](image)'))
assert($('svg[viewBox="0 0 100 100"] > foreignObject').length === 2)
assert($('svg[viewBox="0 0 100 100"] > foreignObject').length === 3)

const bg = $('svg > foreignObject:first-child')
const bgSection = bg.find(
Expand All @@ -134,7 +134,9 @@ describe('Marpit background image plugin', () => {

it('assigns data attribute to section element of the slide content', () => {
const $ = $load(mdSVG().render('![bg](image)\n\n# test'))
const slideSection = $('svg > foreignObject:last-child > section')
const slideSection = $(
'svg > foreignObject > section[data-marpit-advanced-background="content"]'
)

assert(slideSection.find('h1').length === 1)
assert(slideSection.attr('data-marpit-advanced-background') === 'content')
Expand Down Expand Up @@ -174,24 +176,28 @@ describe('Marpit background image plugin', () => {
splitBackgroundKeywords.forEach(keyword => {
context(`with the ${keyword} keyword for split background`, () => {
const $ = $load(mdSVG().render(`![bg ${keyword}](image)`))
const foreignObject = $('svg > foreignObject:last-child')
const section = $(
'svg > foreignObject > section[data-marpit-advanced-background="content"]'
)
const foreignObject = section.parent()

it('assigns the width attribute of foreignObject for content as 50%', () => {
assert(foreignObject.attr('width') === '50%')
})
it('assigns the width attribute of foreignObject for content as 50%', () =>
assert(foreignObject.attr('width') === '50%'))

it('assigns data attribute of the keyword for split background', () => {
const section = foreignObject.find('> section')
it('assigns data attribute of the keyword for split background', () =>
assert(
section.attr('data-marpit-advanced-background-split') === keyword
)
})
))
})
})

it('assigns x attribute of foreignObject for content as 50% with left keyword', () => {
const $ = $load(mdSVG().render(`![bg left](image)`))
const foreignObject = $('svg > foreignObject:last-child')
const section = $(
'svg > foreignObject > section[data-marpit-advanced-background="content"]'
)
const foreignObject = section.parent()

assert(foreignObject.attr('x') === '50%')
})

Expand All @@ -201,7 +207,9 @@ describe('Marpit background image plugin', () => {
const $ = $load(mdSVG().render(`![bg right](a) ![bg left](b)`))

it('uses the last defined keyword', () => {
const section = $('svg > foreignObject:last-child > section')
const section = $(
'svg > foreignObject > section[data-marpit-advanced-background="content"]'
)
assert(
section.attr('data-marpit-advanced-background-split') === 'left'
)
Expand Down Expand Up @@ -292,17 +300,13 @@ describe('Marpit background image plugin', () => {
context('with paginate directive', () => {
const $ = $load(mdSVG().render('<!-- paginate: true --> ![bg](test)'))

it('appends <foreignObject data-marpit-advanced-background="pagination"> to last', () => {
it('assigns data-marpit-pagination attribute to pseudo layer', () => {
const foreignObjects = $('svg > foreignObject')
assert(foreignObjects.length === 3)

const lastFO = foreignObjects.eq(2)
assert(lastFO.is('[data-marpit-advanced-background="pagination"]'))
assert(
lastFO
.find('> section')
.is('[data-marpit-advanced-background="pagination"]')
)
assert(lastFO.is('[data-marpit-advanced-background="pseudo"]'))
assert(lastFO.find('> section').is('[data-marpit-pagination="1"]'))
})
})
})
Expand Down