indvd00m@0: CrossReference Plugin for CKEditor 4 indvd00m@0: ================================= indvd00m@0: indvd00m@0: Adds cross references links with optional auto-numeration for chapters, images, tables and references. Other types of references can be defined in config. indvd00m@0: indvd00m@2: ## Online demo indvd00m@2: indvd00m@2: Try the plugin demo at . indvd00m@2: indvd00m@0: ## Description indvd00m@0: indvd00m@0: Two main conceptions - anchor and link to anchor. There are 4 type of references defined by default: chapter, image, table, reference. Example of anchor of type `image` in raw html: indvd00m@0: ```html indvd00m@0: indvd00m@0: Fig. 1. Experimental result. indvd00m@0: indvd00m@0: ``` indvd00m@0: Example of link to this anchor in raw html: indvd00m@0: ```html indvd00m@0: indvd00m@0: 1 indvd00m@0: indvd00m@0: ``` indvd00m@0: After every inserting of anchor or links to anchor all references will be updated to be a concerted. Or you can manually update cross-references by selecting option in menu (for example after deleting of anchors). indvd00m@0: indvd00m@0: ## Configuration indvd00m@0: indvd00m@0: You can switch which types is active by config option `config.crossreference.activeTypes = ['type1', 'type2']`. You can define other types also. indvd00m@0: indvd00m@0: ### Default config: indvd00m@0: indvd00m@0: ```javascript indvd00m@0: { indvd00m@0: activeTypes: ['chapter', 'image', 'table', 'reference'], indvd00m@0: overrideTypes: false, indvd00m@0: types: { indvd00m@0: chapter: { indvd00m@0: name: 'Chapter', indvd00m@0: anchorTextTemplate: '${number}. ${name}.', indvd00m@0: linkTextTemplate: '${number}', indvd00m@0: numeration: { indvd00m@0: enabled: true, indvd00m@0: firstNumber: '1', indvd00m@0: increase: function(number) { indvd00m@0: var n = parseInt(number); indvd00m@0: return ++n; indvd00m@0: } indvd00m@0: }, indvd00m@0: anchorsProvider: 'default', indvd00m@0: allowCreateAnchors: true, indvd00m@0: groupAnchors: false indvd00m@0: }, indvd00m@0: image: { indvd00m@0: name: 'Figure', indvd00m@0: anchorTextTemplate: 'Fig. ${number}. ${name}.', indvd00m@0: linkTextTemplate: '${number}', indvd00m@0: numeration: { indvd00m@0: enabled: true, indvd00m@0: firstNumber: '1', indvd00m@0: increase: function(number) { indvd00m@0: var n = parseInt(number); indvd00m@0: return ++n; indvd00m@0: } indvd00m@0: }, indvd00m@0: anchorsProvider: 'default', indvd00m@0: allowCreateAnchors: true, indvd00m@0: groupAnchors: false indvd00m@0: }, indvd00m@0: table: { indvd00m@0: name: 'Table', indvd00m@0: anchorTextTemplate: 'Table ${number}. ${name}.', indvd00m@0: linkTextTemplate: '${number}', indvd00m@0: numeration: { indvd00m@0: enabled: true, indvd00m@0: firstNumber: '1', indvd00m@0: increase: function(number) { indvd00m@0: var n = parseInt(number); indvd00m@0: return ++n; indvd00m@0: } indvd00m@0: }, indvd00m@0: anchorsProvider: 'default', indvd00m@0: allowCreateAnchors: true, indvd00m@0: groupAnchors: false indvd00m@0: }, indvd00m@0: reference: { indvd00m@0: name: 'Reference', indvd00m@0: anchorTextTemplate: '[${number}] ${name}.', indvd00m@0: linkTextTemplate: '[${number}]', indvd00m@0: numeration: { indvd00m@0: enabled: true, indvd00m@0: firstNumber: '1', indvd00m@0: increase: function(number) { indvd00m@0: var n = parseInt(number); indvd00m@0: return ++n; indvd00m@0: } indvd00m@0: }, indvd00m@0: anchorsProvider: 'default', indvd00m@0: allowCreateAnchors: true, indvd00m@0: groupAnchors: false indvd00m@0: } indvd00m@0: } indvd00m@0: } indvd00m@0: ``` indvd00m@0: | Property | Description | Type | Default value | indvd00m@0: | --- | --- | --- | --- | indvd00m@0: | `activeTypes` | Which type of anchors would be activated. | Array | `['chapter', 'image', 'table', 'reference']` | indvd00m@0: | `overrideTypes` | If you define your own types, enabling this option lead to mixing of your types with types from default config which not yet defined in your config. | Boolean | false | indvd00m@0: | `types` | Types definition. | Object | see [Default config](https://github.com/indvd00m/crossreference#default-config) section| indvd00m@0: indvd00m@0: ### Example of type definition indvd00m@0: indvd00m@0: ```javascript indvd00m@0: image: { indvd00m@0: name: 'Figure', indvd00m@0: anchorTextTemplate: 'Fig. ${number}. ${name}.', indvd00m@0: linkTextTemplate: '${number}', indvd00m@0: numeration: { indvd00m@0: enabled: true, indvd00m@0: firstNumber: '1', indvd00m@0: increase: function(number) { indvd00m@0: var n = parseInt(number); indvd00m@0: return ++n; indvd00m@0: } indvd00m@0: }, indvd00m@0: anchorsProvider: 'default', indvd00m@0: allowCreateAnchors: true, indvd00m@0: groupAnchors: false indvd00m@0: } indvd00m@0: ``` indvd00m@0: | Property | Description | Type | Required | indvd00m@0: | --- | --- | --- | --- | indvd00m@0: | `name` | Type name. | String | Yes | indvd00m@0: | `anchorTextTemplate` | Template for anchor text. This text will be put in `a` tag. You can use variables in format `${variableName}`. Variables is a properties of an anchor object (see [Example of an anchor object](https://github.com/indvd00m/crossreference#example-of-an-anchor-object) section). | String | No | indvd00m@0: | `linkTextTemplate` | Template for link text. This text will be put in `a` tag. You can use variables in format `${variableName}`. Variables is a properties of an anchor object (see [Example of an anchor object](https://github.com/indvd00m/crossreference#example-of-an-anchor-object) section). | String | No | indvd00m@2: | `numeration` | Definition of type numeration. See [Example of a numeration definition](https://github.com/indvd00m/crossreference#example-of-a-numeration-definition) section. | Object | No | indvd00m@0: | `anchorsProvider` | See [Example of type with anchors provider](https://github.com/indvd00m/crossreference#example-of-type-with-anchors-provider) section. | String 'default' or function | No | indvd00m@0: | `allowCreateAnchors` | Can user create anchors of this type in anchors dialog. | Boolean | No | indvd00m@0: | `groupAnchors` | If `true`, anchors can be filtered by group in link dialog. | Boolean | No | indvd00m@0: indvd00m@0: ### Example of a numeration definition indvd00m@0: indvd00m@0: ```javascript indvd00m@0: numeration: { indvd00m@0: enabled: true, indvd00m@0: firstNumber: '1', indvd00m@0: increase: function(number) { indvd00m@0: var n = parseInt(number); indvd00m@0: return ++n; indvd00m@0: } indvd00m@0: } indvd00m@0: ``` indvd00m@0: | Property | Description | Type | indvd00m@0: | --- | --- | --- | indvd00m@0: | `enabled` | Enabling/disabling numeration of anchors. | Boolean | indvd00m@0: | `firstNumber` | First number. For example you may define `firstNumber` as `I` for Roman numerals. | String | indvd00m@0: | `increase` | Function which must return number (as string) which is next after `number` argument (string). | Function | indvd00m@0: indvd00m@0: ### Example of an anchor object indvd00m@0: indvd00m@0: JSON object: indvd00m@0: indvd00m@0: ```javascript indvd00m@0: { indvd00m@0: type: 'image', indvd00m@0: guid: '7d24373b-0756-481d-bf97-5a17ffdf3a28', indvd00m@0: name: 'Experimental result', indvd00m@0: number: '1', indvd00m@0: text: 'Fig. 1. Experimental result.', indvd00m@0: groupName: 'Group name', indvd00m@0: groupGuid: '6c848dff-cde3-421f-b926-695c8de37d80' indvd00m@0: } indvd00m@0: ``` indvd00m@0: | Property | Description | Type | Required | indvd00m@0: | --- | --- | --- | --- | indvd00m@0: | `type` | Type name of this anchor (`config.types.typeName`). | String | Yes | indvd00m@0: | `guid` | Unique guid of this anchor. | String | Yes | indvd00m@0: | `name` | Name of this anchor. | String | Yes | indvd00m@0: | `number` | Number of this anchor (if type contains numeration definition). | String | Depends of type | indvd00m@0: | `text` | Text of this anchor. Optional property because of text will generated by `type.anchorTextTemplate` template. | String | No | indvd00m@0: | `groupName` | Name of anchor group. | String | No | indvd00m@0: | `groupGuid` | Unique guid of anchor group. | String | No | indvd00m@0: indvd00m@0: ### Example of type with anchors provider indvd00m@0: indvd00m@0: You can define your own anchors provider. By default plugin search anchors in content of editor and use this anchors for links. But if you want refer to anchors outside of editor you can define another type of anchor with `anchorsProvider` function. indvd00m@0: indvd00m@0: ```javascript indvd00m@0: myType: { indvd00m@0: name: 'My type', indvd00m@0: anchorTextTemplate: '${name}', indvd00m@0: linkTextTemplate: '${name}', indvd00m@0: anchorsProvider: function(callback, editorAnchors, type, editor) { indvd00m@0: var anchors = []; indvd00m@0: anchors.push({ indvd00m@0: type: 'myType', indvd00m@0: guid: '7d24373b-0756-481d-bf97-5a17ffdf3a28', indvd00m@0: name: 'Anchor name', indvd00m@0: number: '1' indvd00m@0: }); indvd00m@0: callback(anchors); indvd00m@0: }, indvd00m@0: allowCreateAnchors: false, indvd00m@0: groupAnchors: false indvd00m@0: }, indvd00m@0: ``` indvd00m@0: indvd00m@0: `anchorsProvider` method attributes: indvd00m@0: indvd00m@0: | Name | Description | Type | indvd00m@0: | --- | --- | --- | indvd00m@0: | `callback` | Callback method which must be called with arrays of anchors as argument. | Function | indvd00m@0: | `editorAnchors` | Anchors of this type (`myType` in this case) which already contains in editor. You can merge this anchors with your own anchors if need. | Array | indvd00m@0: | `type` | Type definition (Object `myType` in this case). | Object | indvd00m@0: | `editor` | Instance of ckeditor. | Object | indvd00m@0: indvd00m@0: indvd00m@0: ## Requirements indvd00m@0: indvd00m@0: CrossReference Plugin require CKEditor 4.5+ version and dependent from plugins: dialog, notification. indvd00m@0: indvd00m@0: ## Installation indvd00m@0: indvd00m@2: 1. Download the plugin: https://github.com/indvd00m/crossreference/releases. indvd00m@0: indvd00m@0: 2. Extract (decompress) the downloaded file into the plugins folder of your indvd00m@0: CKEditor installation. indvd00m@0: Example: http://example.com/ckeditor/plugins/crossreference indvd00m@0: indvd00m@0: 3. Enable the plugin by using the extraPlugins configuration setting. indvd00m@0: Example: CKEDITOR.config.extraPlugins = 'crossreference'; indvd00m@0: indvd00m@0: ## Roadmap indvd00m@0: indvd00m@0: See https://github.com/indvd00m/crossreference/issues. indvd00m@0: indvd00m@0: ## Icons: indvd00m@2: indvd00m@2: https://icons8.com/web-app/21792/unicast indvd00m@2: indvd00m@0: https://icons8.com/web-app/15117/anchor indvd00m@0: indvd00m@0: https://icons8.com/web-app/38051/link indvd00m@0: indvd00m@0: https://icons8.com/web-app/21100/refresh indvd00m@0: indvd00m@0: ## License & Author indvd00m@0: indvd00m@0: CrossReference Plugin is distributed under GPL/LGPL/MPL. For license terms, see LICENSE.md. indvd00m@0: indvd00m@0: CrossReference Plugin is written by David E. Veliev.