diff --git a/src/Passage.js b/src/Passage.js
index 0d65b19c..8a609a09 100644
--- a/src/Passage.js
+++ b/src/Passage.js
@@ -221,7 +221,7 @@ export default class Passage {
*/
toTwine2HTML() {
// Start the passage element
- const passageData = '\t 1) {
- passageData += ` tags="${this.#_tags.join(' ')}" `;
- } else if (passage.tags.length === 1) {
- passageData += ` tags="${this.#_tags[0]}" `;
- }
+ passageData += ` tags="${this.#_tags.join(' ')}" `;
/**
* position: (string) Optional.
@@ -260,7 +256,7 @@ export default class Passage {
* when viewed within the Twine 2 editor.
*/
if (Object.prototype.hasOwnProperty.call(this.#_metadata, 'size')) {
- storyData += `size="${passage.metadata.size}" `;
+ passageData += `size="${this.#_metadata.size}" `;
}
/**
@@ -269,10 +265,6 @@ export default class Passage {
* @returns {string} Escaped text.
*/
const escape = function (text) {
- // Throw error if text is not a string
- if (Object.prototype.toString.call(text) !== '[object String]') {
- throw new Error('Text argument is not a String');
- }
const rules = [
['&', '&'],
@@ -291,9 +283,67 @@ export default class Passage {
}
// Add the text and close the element.
- passageData += `>${escape(passage.text)}\n`;
+ passageData += `>${escape(this.text)}\n`;
// Return the Twine 2 HTML element.
return passageData;
}
+
+ /**
+ * Return Twine 1 HTML representation.
+ * @public
+ * @function toTwine2HTML
+ * @returns {string} Twine 1 HTML string.
+ */
+ toTwine1HTML() {
+ /**
+ *
[[One passage]]
+ */
+ // Start the passage element
+ let passageData = '\t${this.#_text}
`;
+
+ // Return the HTML representation.
+ return passageData;
+ }
}
diff --git a/test/Passage.test.js b/test/Passage.test.js
index 458e0bfb..91a82e32 100644
--- a/test/Passage.test.js
+++ b/test/Passage.test.js
@@ -1,7 +1,7 @@
import Passage from '../src/Passage.js';
describe('Passage', () => {
- describe('#constructor()', () => {
+ describe('constructor()', () => {
it('Set default values', () => {
const p = new Passage();
expect(p.name).toBe('');
@@ -112,4 +112,81 @@ describe('Passage', () => {
expect(Object.keys(r.metadata).length).toBe(0);
});
});
+
+ describe('toTwine2HTML()', function() {
+
+ let p = null;
+ let result = null;
+
+ beforeEach(() => {
+ p = new Passage("Test", "Word", ['tag1'], {'some': 'thing'}, 10);
+ result = p.toTwine2HTML();
+ });
+
+ it('Should contain PID', function() {
+ expect(result.includes('pid="10"')).toBe(true);
+ });
+
+ it('Should include name', function() {
+ expect(result.includes('name="Test"')).toBe(true);
+ });
+
+ it('Should include single tag', function() {
+ expect(result.includes('tags="tag1"')).toBe(true);
+ });
+
+ it('Should include multiple tags', function() {
+ p.tags = ['tag1', 'tag2'];
+ result = p.toTwine2HTML();
+ expect(result.includes('tags="tag1 tag2"')).toBe(true);
+ });
+
+ it('Should include position, if it exists', function() {
+ p.metadata = {'position': "102,99"};
+ result = p.toTwine2HTML();
+ expect(result.includes('position="102,99"')).toBe(true);
+ });
+
+ it('Should include size, if it exists', function() {
+ p.metadata = {'size': "100,100"};
+ result = p.toTwine2HTML();
+ expect(result.includes('size="100,100"')).toBe(true);
+ });
+ });
+
+ describe('toTwine1HTML()', function() {
+ let p = null;
+ let result = null;
+
+ beforeEach(() => {
+ p = new Passage("Test", "Word", ['tag1'], {'position': '12, 12'});
+ result = p.toTwine1HTML();
+ });
+
+ it('Should include tiddler', function() {
+ expect(result.includes('tiddler="Test"')).toBe(true);
+ });
+
+ it('Should include single tag', function() {
+ expect(result.includes('tags="tag1"')).toBe(true);
+ });
+
+ it('Should include multiple tags', function() {
+ p.tags = ['tag1', 'tag2'];
+ result = p.toTwine1HTML();
+ expect(result.includes('tags="tag1 tag2"')).toBe(true);
+ });
+
+ it('Should include position, if it exists', function() {
+ p.metadata = {'position': "102,99"};
+ result = p.toTwine1HTML();
+ expect(result.includes('position="102,99"')).toBe(true);
+ });
+
+ it('Should use default position', function() {
+ p.metadata = {};
+ result = p.toTwine1HTML();
+ expect(result.includes('position="10,10"')).toBe(true);
+ });
+ });
});