Skip to content
Closed
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
5 changes: 3 additions & 2 deletions aio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@
"lighthouse": "^1.6.3",
"lodash": "^4.17.4",
"protractor": "~5.1.0",
"rehype": "^4.0.0",
"rehype-autolink-headings": "^2.0.0",
"rehype-slug": "^2.0.0",
"remark": "^7.0.0",
"remark-autolink-headings": "^4.0.0",
"remark-html": "^6.0.0",
"remark-slug": "^4.2.2",
"rho": "https://github.com/petebacondarwin/rho#master",
"rimraf": "^2.6.1",
"shelljs": "^0.7.7",
Expand Down
8 changes: 0 additions & 8 deletions aio/src/styles/1-layouts/_sidenav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,6 @@ md-sidenav-container div.mat-sidenav-content {
width: 100%;
}

.mat-icon, .material-icons {
display: inline-block;
position: absolute;
top: 6px;
right: 8px;
color: $mediumgray;
}

.heading-children.expanded {
visibility: visible;
opacity: 1;
Expand Down
9 changes: 7 additions & 2 deletions aio/src/styles/2-modules/_code.scss
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,22 @@ aio-code.headed-code {
}

.copy-button {
display: inline-block;
position: absolute;
top: 6px;
right: 8px;

color: $lightgray;
background-color: transparent;
border: none;
cursor: pointer;
&:hover {
color: $mediumgray;
}

@media (max-width: 480px) {
top: 0;
bottom: 0;
right: 0;
}
}

Expand Down
69 changes: 35 additions & 34 deletions aio/src/styles/2-modules/_heading-anchors.scss
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
h1, h2, h3, h4, h5, h6 {
.icon-link {
color: $darkgray;
vertical-align: middle;
visibility: hidden;
margin: 8px;
.sidenav-content {
h1, h2, h3, h4, h5, h6 {

font: normal normal 24px 'Material Icons';
display: inline-block;
line-height: 1;
text-transform: none;
letter-spacing: normal;
word-wrap: normal;
white-space: nowrap;
direction: ltr;
.mat-icon, .material-icons {
visibility: hidden;
display: inline-block;
color: $mediumgray;
margin: 0 8px;
}

/* Support for all WebKit browsers. */
-webkit-font-smoothing: antialiased;
/* Support for Safari and Chrome. */
text-rendering: optimizeLegibility;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does @sjtrimble know you did this? 😁

&:hover {
.mat-icon, .material-icons {
visibility: visible;
}
}

/* Support for Firefox. */
-moz-osx-font-smoothing: grayscale;

/* Support for IE. */
font-feature-settings: 'liga';

&:before { content: 'link'; }
a {
text-decoration: none;
padding-left: 8px;
margin-left: -50px;
display: inline-block;
vertical-align: middle;
}
}

a {
text-decoration: none;
padding-left: 8px;
margin-left: -50px;
display: inline-block;
vertical-align: middle;
.l-sub-section {
h1, h2, h3, h4, h5, h6 {
a {
padding-right: 24px;
margin-left: -74px;
}
}
}

&:hover .icon-link {
visibility: visible
.alert {
h1, h2, h3, h4, h5, h6 {
a {
padding-right: 40px;
margin-left: -90px;
}
}
}
}
}
3 changes: 2 additions & 1 deletion aio/tools/transforms/angular-api-package/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ module.exports = new Package('angular-api', [basePackage, typeScriptPackage])
});
})

.config(function(convertToJsonProcessor, EXPORT_DOC_TYPES) {
.config(function(convertToJsonProcessor, postProcessHtml, EXPORT_DOC_TYPES) {
const DOCS_TO_CONVERT = EXPORT_DOC_TYPES.concat([
'decorator', 'directive', 'pipe', 'module'
]);
convertToJsonProcessor.docTypes = convertToJsonProcessor.docTypes.concat(DOCS_TO_CONVERT);
postProcessHtml.docTypes = convertToJsonProcessor.docTypes.concat(DOCS_TO_CONVERT);
});
10 changes: 9 additions & 1 deletion aio/tools/transforms/angular-base-package/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ const linksPackage = require('../links-package');
const examplesPackage = require('../examples-package');
const targetPackage = require('../target-package');
const remarkPackage = require('../remark-package');
const postProcessPackage = require('../post-process-package');

const { PROJECT_ROOT, DOCS_OUTPUT_PATH, TEMPLATES_PATH, requireFolder } = require('../config');

module.exports = new Package('angular-base', [
jsdocPackage, nunjucksPackage, linksPackage, examplesPackage, targetPackage, remarkPackage
jsdocPackage, nunjucksPackage, linksPackage, examplesPackage, targetPackage, remarkPackage, postProcessPackage
])

// Register the processors
Expand Down Expand Up @@ -112,6 +113,13 @@ module.exports = new Package('angular-base', [
];
})


.config(function(postProcessHtml) {
postProcessHtml.plugins = [
require('./post-processors/autolink-headings')
];
})

.config(function(convertToJsonProcessor) {
convertToJsonProcessor.docTypes = [];
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const slug = require('rehype-slug');
const link = require('rehype-autolink-headings');

/**
* Get remark to inject anchors into headings
*/
module.exports = [
slug,
[link, {
properties: {
title: 'Link to this heading',
className: ['header-link'],
'aria-hidden': 'true'
},
content: {
type: 'element',
tagName: 'i',
properties: {className: ['material-icons']},
children: [{ type: 'text', value: 'link' }]
}
}]
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const processorFactory = require('../../post-process-package/processors/post-process-html');
const plugin = require('./autolink-headings');

describe('autolink-headings postprocessor', () => {
let processor;

beforeEach(() => {
processor = processorFactory();
processor.docTypes = ['a'];
processor.plugins = [plugin];
});

it('should add anchors to headings', () => {
const docs = [ {
docType: 'a',
renderedContent: `
<h1>Heading 1</h2>
<h2>Heading with <strong>bold</strong></h2>
<h3>Heading with encoded chars &#x26;</h3>
`
}];
processor.$process(docs);
expect(docs[0].renderedContent).toEqual(`
<h1 id="heading-1"><a title="Link to this heading" class="header-link" aria-hidden="true" href="#heading-1"><i class="material-icons">link</i></a>Heading 1</h1>
<h2 id="heading-with-bold"><a title="Link to this heading" class="header-link" aria-hidden="true" href="#heading-with-bold"><i class="material-icons">link</i></a>Heading with <strong>bold</strong></h2>
<h3 id="heading-with-encoded-chars-"><a title="Link to this heading" class="header-link" aria-hidden="true" href="#heading-with-encoded-chars-"><i class="material-icons">link</i></a>Heading with encoded chars &#x26;</h3>
`);
});
});

3 changes: 2 additions & 1 deletion aio/tools/transforms/angular-content-package/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ module.exports = new Package('angular-content', [basePackage, contentPackage])
})

// We want the content files to be converted
.config(function(convertToJsonProcessor) {
.config(function(convertToJsonProcessor, postProcessHtml) {
convertToJsonProcessor.docTypes.push('content');
postProcessHtml.docTypes.push('content');
});
5 changes: 5 additions & 0 deletions aio/tools/transforms/post-process-package/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var Package = require('dgeni').Package;
var base = require('dgeni-packages/base');

module.exports = new Package('post-process-package', [base])
.processor(require('./processors/post-process-html'));
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const rehype = require('rehype');

/**
* @dgProcessor postProcessHtml
*
* @description
* Use the rehype processing engine to manipulate the
* `renderedContent` HTML via rehype "plugins" that work with HTML ASTs (HASTs).
* See https://github.com/wooorm/rehype
*
* Each plugin is a factory function that will be called with the "rehype" engine as `this`.
* The factory should return a function that takes a HAST and returns a `boolean` or `undefined`.
* The HAST can be mutated by the this function.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the this --> the or this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The this variable

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think you meant "The HAST can be mutated by this function(where "this function" is the _"function that takes a HAST and returns abooleanorundefined`"_, which in turn is returned by the plugin factory function) 😁

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah :-)

* If `false` is returned then the processing stops with that plugin.
*
* @property docTypes {string[]} the `docTypes` of docs that should be post-processed
* @property plugins {Function[]} the rehype plugins that will modify the HAST.
*
*/
module.exports = function postProcessHtml() {
return {
$runAfter: ['docs-rendered'],
$runBefore: ['writing-files'],
docTypes: [],
plugins: [],
$process(docs) {
const engine = rehype()
.data('settings', { fragment: true });
this.plugins.forEach(plugin => engine.use(plugin));

docs
.filter(doc => this.docTypes.indexOf(doc.docType) !== -1)
.forEach(doc =>
doc.renderedContent = engine.processSync(doc.renderedContent).contents);
}
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const testPackage = require('../../helpers/test-package');
const Dgeni = require('dgeni');

describe('postProcessHtml', function() {
let dgeni, injector, processor;

beforeEach(function() {
dgeni = new Dgeni([testPackage('post-process-package', true)]);
injector = dgeni.configureInjector();
processor = injector.get('postProcessHtml');
processor.docTypes = ['a', 'b'];
});

it('should be available from the injector', () => {
expect(processor).toBeDefined();
});

it('should only process docs that match the specified docTypes', () => {
const elements = [];
const captureFirstElement = ast => {
elements.push(ast.children[0].tagName);
};
processor.plugins = [() => captureFirstElement];

const docs = [
{ docType: 'a', renderedContent: '<a></a>' },
{ docType: 'b', renderedContent: '<b></b>' },
{ docType: 'c', renderedContent: '<c></c>' },
{ docType: 'd', renderedContent: '<d></d>' },
];
processor.$process(docs);
expect(elements).toEqual(['a', 'b']);
});

it('should run all the plugins on each doc', () => {
const capitalizeFirstElement = ast => {
ast.children[0].tagName = ast.children[0].tagName.toUpperCase();
};
const addOneToFirstElement = ast => {
ast.children[0].tagName = ast.children[0].tagName + '1';
};
const elements = [];
const captureFirstElement = ast => {
elements.push(ast.children[0].tagName);
};

const docs = [
{ docType: 'a', renderedContent: '<a></a>' },
{ docType: 'b', renderedContent: '<b></b>' },
{ docType: 'c', renderedContent: '<c></c>' },
{ docType: 'd', renderedContent: '<d></d>' },
];

processor.plugins = [
() => capitalizeFirstElement,
() => addOneToFirstElement,
() => captureFirstElement
];
processor.$process(docs);
expect(elements).toEqual(['A1', 'B1']);
});
});
11 changes: 0 additions & 11 deletions aio/tools/transforms/remark-package/services/renderMarkdown.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const remark = require('remark');
const slug = require('remark-slug');
const autolinkHeadings = require('remark-autolink-headings');
const html = require('remark-html');

/**
Expand All @@ -17,8 +15,6 @@ module.exports = function renderMarkdown() {
// .use(() => tree => {
// console.log(require('util').inspect(tree, { colors: true, depth: 4 }));
// })
.use(slug)
.use(autolinkHeadings)
.use(html);

return function renderMarkdownImpl(content) {
Expand Down Expand Up @@ -107,13 +103,6 @@ module.exports = function renderMarkdown() {
}
};








/**
* matchRecursiveRegExp
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('remark: renderMarkdown service', () => {
const output = renderMarkdown(content);

expect(output).toEqual(
'<h1 id="heading-1"><a href="#heading-1" aria-hidden="true"><span class="icon icon-link"></span></a>heading 1</h1>\n' +
'<h1>heading 1</h1>\n' +
'<p>A paragraph with <strong>bold</strong> and <em>italic</em>.</p>\n' +
'<ul>\n' +
'<li>List item 1</li>\n' +
Expand Down Expand Up @@ -67,14 +67,4 @@ describe('remark: renderMarkdown service', () => {
const output = renderMarkdown(content);
expect(output).toEqual('<p>some text</p>\n<p> indented text</p>\n<p>other text</p>\n');
});

it('should add id slugs and links to headings', () => {
const content = '# heading 1\n\nSome text\n\n## heading 2\n\nMore text';
const output = renderMarkdown(content);
expect(output).toEqual(
'<h1 id="heading-1"><a href="#heading-1" aria-hidden="true"><span class="icon icon-link"></span></a>heading 1</h1>\n' +
'<p>Some text</p>\n' +
'<h2 id="heading-2"><a href="#heading-2" aria-hidden="true"><span class="icon icon-link"></span></a>heading 2</h2>\n' +
'<p>More text</p>\n');
});
});
Loading