Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
chore(website): better handle @link and @linkplain
Browse files Browse the repository at this point in the history
  • Loading branch information
sjelin committed Jun 30, 2015
1 parent 9267f45 commit 3442314
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
4 changes: 4 additions & 0 deletions website/css/protractor.less
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
@child-color: #777;
@mobile-menu-margin: 15px;

a code {
color: inherit;
}

.protractor-container {
margin-bottom: 50px;
padding-top: @padding-top;
Expand Down
15 changes: 10 additions & 5 deletions website/docgen/processors/add-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ var addLinkToLinkAnnotation = function(str, doc) {
var oldStr = null;
while (str != oldStr) {
oldStr = str;
var matches = /{\s*@link\s+([^]+?)\s*}/.exec(str);
var matches = /{\s*@link[plain]*\s+([^]+?)\s*}/.exec(str);
if (matches) {
var str = str.replace(
new RegExp('{\\s*@link\\s+' +
new RegExp('{\\s*@link[plain]*\\s+' +
matches[1].replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') + '\\s*}'),
toMarkdownLinkFormat(matches[1], doc)
toMarkdownLinkFormat(matches[1], doc,
matches[0].indexOf('linkplain') == -1)
);
}
}
Expand All @@ -75,7 +76,7 @@ var escape = function(str) {
* @param {!Object} doc Current document.
* @return {string} A link for the type.
*/
var toMarkdownLinkFormat = function(link, doc) {
var toMarkdownLinkFormat = function(link, doc, code) {
var type, desc;

// Split type and description
Expand All @@ -86,6 +87,10 @@ var toMarkdownLinkFormat = function(link, doc) {
desc = link.substr(i).trim();
type = link.substr(0, i).trim();
}
if (code) {
desc = '{@code ' + desc + '}'
}
desc = desc.replace(new RegExp('\n', 'g'), ' ');

if (!type.match(/^https?:\/\//)) {
// Remove extra '()' at the end of types
Expand All @@ -99,7 +104,7 @@ var toMarkdownLinkFormat = function(link, doc) {
}

// Replace '#' in the middle of types with '.'
type = type.replace(new RegExp('#', 'g'), '.');
type = type.replace(new RegExp('#', 'g'), '.prototype.');

// Only create a link if it's in the API
if (!typeTable[type]) {
Expand Down
16 changes: 8 additions & 8 deletions website/docgen/spec/add-links-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ describe('add-links', function() {

// Then ensure a link was added to the type.
expect(docs[1].description).
toBe('A promise that [webdriver.WebElement](webdriver.WebElement)s');
toBe('A promise that [{@code webdriver.WebElement}](webdriver.WebElement)s');
expect(docs[1].returns.description).
toBe('A promise located [webdriver.WebElement](webdriver.WebElement)s.');
toBe('A promise located [{@code webdriver.WebElement}](webdriver.WebElement)s.');
});

it('should handle {@link type desc} links', function() {
Expand Down Expand Up @@ -217,9 +217,9 @@ describe('add-links', function() {

// Then ensure a link was added to the type.
expect(docs[1].description).
toBe('A promise that [Web Elements](webdriver.WebElement)');
toBe('A promise that [{@code Web Elements}](webdriver.WebElement)');
expect(docs[1].returns.description).
toBe('A promise located Web Elements.');
toBe('A promise located {@code Web Elements}.');
});

it('should handle "#" in @link links', function() {
Expand Down Expand Up @@ -261,9 +261,9 @@ describe('add-links', function() {

// Then ensure a link was added to the type.
expect(docs[1].description).
toBe('A promise that [Web Drivers](webdriver.WebDriver)');
toBe('A promise that [{@code Web Drivers}](webdriver.WebDriver)');
expect(docs[1].returns.description).
toBe('A promise located [Web Elements](webdriver.WebElement).');
toBe('A promise located {@code Web Elements}.');
});

it('should remove extraneous chatacters from @link links', function() {
Expand All @@ -288,7 +288,7 @@ describe('add-links', function() {
canHaveType: true
},
tagName: 'return',
description: 'A promise located {@link webdriver.WebElement Web Elements }.',
description: 'A promise located {@linkplain webdriver.WebElement Web Elements }.',
startingLine: 119,
typeExpression: 'webdriver.WebElement',
type: {
Expand All @@ -305,7 +305,7 @@ describe('add-links', function() {

// Then ensure a link was added to the type.
expect(docs[1].description).
toBe('A promise that [webdriver.WebElement()](webdriver.WebElement)');
toBe('A promise that [{@code webdriver.WebElement()}](webdriver.WebElement)');
expect(docs[1].returns.description).
toBe('A promise located [Web Elements](webdriver.WebElement).');

Expand Down

0 comments on commit 3442314

Please sign in to comment.