-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,322 additions
and
14,987 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# texture-xmlschema | ||
# texture-xml-utils | ||
|
||
Toolset for working with xml schemas. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const path = require('path') | ||
const fs = require('fs') | ||
const xmlSchemaToMarkdown = require('./xmlSchemaToMarkdown') | ||
|
||
// ATTENTION: this is still very experimental and should be improved if | ||
// we are going to use it more widely | ||
module.exports = function compileSchema (b, name, rngFile, searchDirs = [], deps = [], options = {}) { | ||
const DEST = `tmp/${name}.data.js` | ||
const ISSUES = `tmp/${name}.issues.txt` | ||
const SCHEMA = `tmp/${name}.schema.md` | ||
const rngDir = path.dirname(rngFile) | ||
const entry = path.basename(rngFile) | ||
searchDirs.unshift(rngDir) | ||
b.custom(`Compiling schema '${name}'...`, { | ||
rngFile: [rngFile].concat(deps), | ||
dest: DEST, | ||
execute () { | ||
return new Promise((resolve, reject) => { | ||
setTimeout(() => { | ||
// TODO: make sure that the rngFile exists | ||
const { compileRNG, checkSchema, serializeXMLSchema } = require('..') | ||
const xmlSchema = compileRNG(fs, searchDirs, entry) | ||
b.writeFileSync(DEST, `export default ${serializeXMLSchema(xmlSchema)}`) | ||
b.writeFileSync(SCHEMA, xmlSchemaToMarkdown(xmlSchema)) | ||
if (options.debug) { | ||
const issues = checkSchema(xmlSchema) | ||
const issuesData = [`${issues.length} issues:`, ''].concat(issues).join('\n') | ||
b.writeFileSync(ISSUES, issuesData) | ||
} | ||
resolve() | ||
}, 250) | ||
}) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
module.exports = function xmlSchemaToMD (xmlSchema) { | ||
const { _analyzeSchema } = require('..') | ||
const PRE_START = '<pre style="white-space:pre-wrap;">' | ||
const PRE_END = '</pre>' | ||
|
||
let result = [] | ||
let elementSchemas = xmlSchema._elementSchemas | ||
let elementNames = Object.keys(elementSchemas) | ||
_analyzeSchema(elementSchemas) | ||
|
||
elementNames.sort() | ||
let notImplemented = [] | ||
result.push('# Texture Article') | ||
result.push('') | ||
result.push('This schema defines a strict sub-set of JATS-archiving 1.1 .') | ||
result.push('') | ||
result.push('## Supported Elements') | ||
result.push('') | ||
elementNames.forEach(name => { | ||
let elementSchema = elementSchemas[name] | ||
if (elementSchema.type === 'not-implemented') { | ||
notImplemented.push(elementSchema) | ||
return | ||
} | ||
result.push('### `<' + elementSchema.name + '>`') | ||
if (elementSchema.type === 'not-implemented') { | ||
result.push('Not implemented.') | ||
} else { | ||
let attributes = elementSchema.attributes | ||
let elementSpec = elementSchema.expr.toString() | ||
if (elementSpec.startsWith('(') && elementSpec.endsWith(')')) { | ||
elementSpec = elementSpec.slice(1, -1) | ||
} | ||
if (/^\s*$/.exec(elementSpec)) elementSpec = 'EMPTY' | ||
|
||
let parents = Object.keys(elementSchema.parents) | ||
if (parents.length === 0 && xmlSchema.getStartElement() !== name) { | ||
console.error('Warning: element <%s> is not used.', name) | ||
} | ||
|
||
result.push('') | ||
result.push('**Attributes**:') | ||
result.push(PRE_START) | ||
result.push(Object.keys(attributes).join(', ')) | ||
result.push(PRE_END) | ||
result.push('**Contains**:') | ||
result.push(PRE_START) | ||
result.push(elementSpec) | ||
result.push(PRE_END) | ||
if (parents.length > 0) { | ||
result.push('**This element may be contained in:**') | ||
result.push(PRE_START) | ||
result.push(parents.join(', ')) | ||
result.push(PRE_END) | ||
} | ||
result.push('') | ||
} | ||
}) | ||
if (notImplemented.length > 0) { | ||
result.push('## Not Implemented') | ||
notImplemented.forEach(elementSchema => { | ||
result.push('- ' + elementSchema.name) | ||
}) | ||
} | ||
|
||
return result.join('\n') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './src/index.js' |
Oops, something went wrong.