Implemented `\href' command (#923)

* Implements `\href' command.

* Added `functions/href.js`.
* Added `domTree.anchor` and `buildCommon.makeAnchor` functions.
* Make `buildHTML.getTypeOfDomTree` exported.

* Reflects the code reviews

* Create new argType "url" to treat link string in math appropriately
* Stop using too shorten variable names
* Start using template strings

* Adopts template literal

* Elaborates on glueing

* If-clause restructuring

* Solved confusing explanation

* Allow balanced braces in url

* Adds unit-test for \href

* Adds snapshot tests
This commit is contained in:
Hiromi Ishii
2017-11-24 13:23:35 +09:00
committed by Kevin Barabash
parent 75af19c5bb
commit fd82c4fad0
10 changed files with 335 additions and 2 deletions

View File

@@ -2420,6 +2420,36 @@ describe("An aligned environment", function() {
});
});
describe("An href command", function() {
it("should parse its input", function() {
expect("\\href{http://example.com/}{example here}").toParse();
});
it("should allow letters [#$%&~_^] without escaping", function() {
const url = "http://example.org/~bar/#top?foo=$foo&bar=ba^r_boo%20baz";
const hash = getParsed(`\\href{${url}}{\\alpha}`)[0];
expect(hash.value.href).toBe(url);
});
it("should allow balanced braces in url", function() {
const url = "http://example.org/{too}";
const hash = getParsed(`\\href{${url}}{\\alpha}`)[0];
expect(hash.value.href).toBe(url);
});
it("should not allow unbalanced brace(s) in url", function() {
expect("\\href{http://example.com/{a}{bar}").toNotParse();
expect("\\href{http://example.com/}a}{bar}").toNotParse();
});
it("should allow escape for letters [#$%&~_^{}]", function() {
const url = "http://example.org/~bar/#top?foo=$}foo{&bar=bar^r_boo%20baz";
const input = url.replace(/([#$%&~_^{}])/g, '\\$1');
const ae = getParsed(`\\href{${input}}{\\alpha}`)[0];
expect(ae.value.href).toBe(url);
});
});
describe("A parser that does not throw on unsupported commands", function() {
// The parser breaks on unsupported commands unless it is explicitly
// told not to