ckeditor/plugins/crossreference/README.md
changeset 0 44d330dccc59
child 2 467e24fbc60e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ckeditor/plugins/crossreference/README.md	Thu Dec 15 18:10:20 2016 +0300
     1.3 @@ -0,0 +1,261 @@
     1.4 +CrossReference Plugin for CKEditor 4
     1.5 +=================================
     1.6 +
     1.7 +Adds cross references links with optional auto-numeration for chapters, images, tables and references. Other types of references can be defined in config.
     1.8 +
     1.9 +## Description
    1.10 +
    1.11 +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:
    1.12 +```html
    1.13 +<a 
    1.14 +	class="cross-reference cross-anchor" 
    1.15 +	cross-reference="image" 
    1.16 +	cross-anchor="" 
    1.17 +	cross-guid="7d24373b-0756-481d-bf97-5a17ffdf3a28" 
    1.18 +	cross-name="Experimental result" 
    1.19 +	cross-number="1" 
    1.20 +	name="image-7d24373b-0756-481d-bf97-5a17ffdf3a28"
    1.21 +	>
    1.22 +		Fig. 1. Experimental result.
    1.23 +</a>
    1.24 +```
    1.25 +Example of link to this anchor in raw html:
    1.26 +```html
    1.27 +<a 
    1.28 +	class="cross-reference cross-link" 
    1.29 +	cross-reference="image" 
    1.30 +	cross-link="" 
    1.31 +	cross-guid="7d24373b-0756-481d-bf97-5a17ffdf3a28" 
    1.32 +	cross-name="Experimental result" 
    1.33 +	cross-number="1" 
    1.34 +	href="#image-7d24373b-0756-481d-bf97-5a17ffdf3a28" 
    1.35 +	title="Fig. 1. Experimental result."
    1.36 +	>
    1.37 +		1
    1.38 +</a>
    1.39 +```
    1.40 +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).
    1.41 +
    1.42 +## Configuration
    1.43 +
    1.44 +You can switch which types is active by config option `config.crossreference.activeTypes = ['type1', 'type2']`. You can define other types also.
    1.45 +
    1.46 +### Default config:
    1.47 +
    1.48 +```javascript
    1.49 +{
    1.50 +	activeTypes: ['chapter', 'image', 'table', 'reference'],
    1.51 +	overrideTypes: false,
    1.52 +	types: {
    1.53 +		chapter: {
    1.54 +			name: 'Chapter',
    1.55 +			anchorTextTemplate: '${number}. ${name}.',
    1.56 +			linkTextTemplate: '${number}',
    1.57 +			numeration: {
    1.58 +				enabled: true,
    1.59 +				firstNumber: '1',
    1.60 +				increase: function(number) {
    1.61 +					var n = parseInt(number);
    1.62 +					return ++n;
    1.63 +				}
    1.64 +			},
    1.65 +			anchorsProvider: 'default',
    1.66 +			allowCreateAnchors: true,
    1.67 +			groupAnchors: false
    1.68 +		},
    1.69 +		image: {
    1.70 +			name: 'Figure',
    1.71 +			anchorTextTemplate: 'Fig. ${number}. ${name}.',
    1.72 +			linkTextTemplate: '${number}',
    1.73 +			numeration: {
    1.74 +				enabled: true,
    1.75 +				firstNumber: '1',
    1.76 +				increase: function(number) {
    1.77 +					var n = parseInt(number);
    1.78 +					return ++n;
    1.79 +				}
    1.80 +			},
    1.81 +			anchorsProvider: 'default',
    1.82 +			allowCreateAnchors: true,
    1.83 +			groupAnchors: false
    1.84 +		},
    1.85 +		table: {
    1.86 +			name: 'Table',
    1.87 +			anchorTextTemplate: 'Table ${number}. ${name}.',
    1.88 +			linkTextTemplate: '${number}',
    1.89 +			numeration: {
    1.90 +				enabled: true,
    1.91 +				firstNumber: '1',
    1.92 +				increase: function(number) {
    1.93 +					var n = parseInt(number);
    1.94 +					return ++n;
    1.95 +				}
    1.96 +			},
    1.97 +			anchorsProvider: 'default',
    1.98 +			allowCreateAnchors: true,
    1.99 +			groupAnchors: false
   1.100 +		},
   1.101 +		reference: {
   1.102 +			name: 'Reference',
   1.103 +			anchorTextTemplate: '[${number}] ${name}.',
   1.104 +			linkTextTemplate: '[${number}]',
   1.105 +			numeration: {
   1.106 +				enabled: true,
   1.107 +				firstNumber: '1',
   1.108 +				increase: function(number) {
   1.109 +					var n = parseInt(number);
   1.110 +					return ++n;
   1.111 +				}
   1.112 +			},
   1.113 +			anchorsProvider: 'default',
   1.114 +			allowCreateAnchors: true,
   1.115 +			groupAnchors: false
   1.116 +		}
   1.117 +	}
   1.118 +}
   1.119 +```
   1.120 +| Property | Description | Type | Default value |
   1.121 +| --- | --- | --- | --- |
   1.122 +| `activeTypes` | Which type of anchors would be activated. | Array | `['chapter', 'image', 'table', 'reference']` |
   1.123 +| `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 |
   1.124 +| `types` | Types definition. | Object | see [Default config](https://github.com/indvd00m/crossreference#default-config) section|
   1.125 +
   1.126 +### Example of type definition
   1.127 +
   1.128 +```javascript
   1.129 +image: {
   1.130 +	name: 'Figure',
   1.131 +	anchorTextTemplate: 'Fig. ${number}. ${name}.',
   1.132 +	linkTextTemplate: '${number}',
   1.133 +	numeration: {
   1.134 +		enabled: true,
   1.135 +		firstNumber: '1',
   1.136 +		increase: function(number) {
   1.137 +			var n = parseInt(number);
   1.138 +			return ++n;
   1.139 +		}
   1.140 +	},
   1.141 +	anchorsProvider: 'default',
   1.142 +	allowCreateAnchors: true,
   1.143 +	groupAnchors: false
   1.144 +}
   1.145 +```
   1.146 +| Property | Description | Type | Required |
   1.147 +| --- | --- | --- | --- |
   1.148 +| `name` | Type name. | String | Yes |
   1.149 +| `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 |
   1.150 +| `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 |
   1.151 +| `numeration` | Definition of type numeration. See [Example of a numeration config](https://github.com/indvd00m/crossreference#example-of-a-numeration-config) section. | Object | No |
   1.152 +| `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 |
   1.153 +| `allowCreateAnchors` | Can user create anchors of this type in anchors dialog. | Boolean | No |
   1.154 +| `groupAnchors` | If `true`, anchors can be filtered by group in link dialog. | Boolean | No |
   1.155 +
   1.156 +### Example of a numeration definition
   1.157 +
   1.158 +```javascript
   1.159 +numeration: {
   1.160 +	enabled: true,
   1.161 +	firstNumber: '1',
   1.162 +	increase: function(number) {
   1.163 +		var n = parseInt(number);
   1.164 +		return ++n;
   1.165 +	}
   1.166 +}
   1.167 +```
   1.168 +| Property | Description | Type |
   1.169 +| --- | --- | --- |
   1.170 +| `enabled` | Enabling/disabling numeration of anchors. | Boolean |
   1.171 +| `firstNumber` | First number. For example you may define `firstNumber` as `I` for Roman numerals. | String |
   1.172 +| `increase` | Function which must return number (as string) which is next after `number` argument (string). | Function |
   1.173 +
   1.174 +### Example of an anchor object
   1.175 +
   1.176 +JSON object:
   1.177 +
   1.178 +```javascript
   1.179 +{
   1.180 +	type: 'image',
   1.181 +	guid: '7d24373b-0756-481d-bf97-5a17ffdf3a28',
   1.182 +	name: 'Experimental result',
   1.183 +	number: '1',
   1.184 +	text: 'Fig. 1. Experimental result.',
   1.185 +	groupName: 'Group name',
   1.186 +	groupGuid: '6c848dff-cde3-421f-b926-695c8de37d80'
   1.187 +}
   1.188 +```
   1.189 +| Property | Description | Type | Required |
   1.190 +| --- | --- | --- | --- |
   1.191 +| `type` | Type name of this anchor (`config.types.typeName`). | String | Yes |
   1.192 +| `guid` | Unique guid of this anchor. | String | Yes |
   1.193 +| `name` | Name of this anchor. | String | Yes |
   1.194 +| `number` | Number of this anchor (if type contains numeration definition). | String | Depends of type |
   1.195 +| `text` | Text of this anchor. Optional property because of text will generated by `type.anchorTextTemplate` template. | String | No |
   1.196 +| `groupName` | Name of anchor group. | String | No |
   1.197 +| `groupGuid` | Unique guid of anchor group. | String | No |
   1.198 +
   1.199 +### Example of type with anchors provider
   1.200 +
   1.201 +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.
   1.202 +
   1.203 +```javascript
   1.204 +myType: {
   1.205 +	name: 'My type',
   1.206 +	anchorTextTemplate: '${name}',
   1.207 +	linkTextTemplate: '${name}',
   1.208 +	anchorsProvider: function(callback, editorAnchors, type, editor) {
   1.209 +		var anchors = [];
   1.210 +		anchors.push({
   1.211 +			type: 'myType',
   1.212 +			guid: '7d24373b-0756-481d-bf97-5a17ffdf3a28',
   1.213 +			name: 'Anchor name',
   1.214 +			number: '1'
   1.215 +		});
   1.216 +		callback(anchors);
   1.217 +	},
   1.218 +	allowCreateAnchors: false,
   1.219 +	groupAnchors: false
   1.220 +},
   1.221 +```
   1.222 +
   1.223 +`anchorsProvider` method attributes:
   1.224 +
   1.225 +| Name | Description | Type |
   1.226 +| --- | --- | --- |
   1.227 +| `callback` | Callback method which must be called with arrays of anchors as argument. | Function |
   1.228 +| `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 |
   1.229 +| `type` | Type definition (Object `myType` in this case). | Object |
   1.230 +| `editor` | Instance of ckeditor. | Object |
   1.231 +
   1.232 +
   1.233 +## Requirements
   1.234 +
   1.235 +CrossReference Plugin require CKEditor 4.5+ version and dependent from plugins: dialog, notification.
   1.236 +
   1.237 +## Installation
   1.238 +
   1.239 + 1. Download the plugin.
   1.240 + 
   1.241 + 2. Extract (decompress) the downloaded file into the plugins folder of your
   1.242 +	CKEditor installation.
   1.243 +	Example: http://example.com/ckeditor/plugins/crossreference
   1.244 +	
   1.245 + 3. Enable the plugin by using the extraPlugins configuration setting.
   1.246 +	Example: CKEDITOR.config.extraPlugins = 'crossreference';
   1.247 +
   1.248 +## Roadmap
   1.249 +
   1.250 +See https://github.com/indvd00m/crossreference/issues.
   1.251 +
   1.252 +## Icons:
   1.253 + 
   1.254 +https://icons8.com/web-app/15117/anchor
   1.255 +
   1.256 +https://icons8.com/web-app/38051/link
   1.257 +
   1.258 +https://icons8.com/web-app/21100/refresh
   1.259 +
   1.260 +## License & Author
   1.261 +
   1.262 +CrossReference Plugin is distributed under GPL/LGPL/MPL. For license terms, see LICENSE.md.
   1.263 +
   1.264 +CrossReference Plugin is written by David E. Veliev.