| 1 |
# 8.0 Migration Notes {: #\8.0} |
| 2 |
|
| 3 |
## Overview |
| 4 |
|
| 5 |
In general, there are a couple things to be aware of when upgrading to 8.0. |
| 6 |
|
| 7 |
- Some previously deprecated features are now removed: tabbed code blocks via SuperFences and ExtraRawHTML. These were |
| 8 |
originally deprecated as they are now redundant, and information is provided to allow you to get the same behavior |
| 9 |
as before. |
| 10 |
|
| 11 |
- One of the most invasive changes was adding the support of defining arbitrary attributes on code blocks in |
| 12 |
SuperFences via the brace header format. This caused numerous changes that affects those who define their own custom |
| 13 |
fences. If you are only using the builtin fences provided by SuperFences, you will likely notice no adverse affects, |
| 14 |
but will be able to take advantage of new the new features being offered. |
| 15 |
|
| 16 |
## Better Support for JS Highlighters |
| 17 |
|
| 18 |
- SuperFences adds the ability, when using the brace header format (` ```{.lang .class #id attr=value} `) to add |
| 19 |
arbitrary HTML attributes to code blocks. By default, all classes, IDs and attributes are added to the `code` block |
| 20 |
of the generated output. The one exception is that the default `highlight` class is always added to the top level |
| 21 |
element. |
| 22 |
|
| 23 |
For instance, if a user needed to specify that a line number starts with an attribute `data-linenum-start`, they |
| 24 |
could simply use the brace header format to define this new attribute: |
| 25 |
|
| 26 |
```` |
| 27 |
```{.python data-linenum-start="30"} |
| 28 |
import sys |
| 29 |
``` |
| 30 |
```` |
| 31 |
|
| 32 |
Attributes will only be used when Python Markdown's [`attr_list`][attr-list] extension is enabled. Attributes will |
| 33 |
also be ignored when using Pygments as Pygments doesn't directly support adding IDs or arbitrary attributes. |
| 34 |
|
| 35 |
This allows for more extensive configuration when using JavaScript highlighters. Now users can set the appropriate |
| 36 |
attributes to configure line numbers and other highlighter specific features without the Highlight extension getting |
| 37 |
in the way. |
| 38 |
|
| 39 |
- Some JS highlighters may require attributes and classes to be assigned to the `pre` element, so the |
| 40 |
[Highlight](../../extensions/highlight.md) extension has added a new feature called `code_attr_on_pre`. This new |
| 41 |
option will ensure that custom classes, IDs, and attributes are applied to the `pre` element instead. |
| 42 |
|
| 43 |
- By default, JavaScript ready code blocks would normally have the specified language class prefixed with `language-`. |
| 44 |
This follows the HTML 5 specification, but some highlighters may prefer something different. The prefix can now be |
| 45 |
changed with the new [Highlight](../../extensions/highlight.md) option called `language_prefix`. |
| 46 |
|
| 47 |
## Retired Features |
| 48 |
|
| 49 |
- The legacy tab feature has been removed from SuperFences. This does not mean tab support is dead as the |
| 50 |
[Tabbed](../../extensions/tabbed.md) extension actually provides an even more useful, general purpose, solution. It |
| 51 |
was impossible to keep this legacy feature around, in its current implementation, after the restructure of for |
| 52 |
attribute list support, so we decided to officially retire this already deprecated feature. |
| 53 |
|
| 54 |
- ExtraRawHTML has officially been removed. This extension only existed because Python Markdown did not have the |
| 55 |
feature exposed in a manner that allowed you to use it without including all of their "Extra" extension, now that |
| 56 |
Python Markdown has exposed this extension by itself, there is no longer a reason for us expose it via |
| 57 |
ExtraRawHTML. Please use Python Markdown's [`md_in_html`][md-in-html] extension instead to get the same exact |
| 58 |
functionality. |
| 59 |
|
| 60 |
## Custom Fence Changes |
| 61 |
|
| 62 |
SuperFences made numerous changes so that users who wish not to use Pygments can set arbitrary attributes via the brace |
| 63 |
header format so that can more extensively configure their code blocks for JavaScript syntax highlighters. This required |
| 64 |
changes to how custom fences were handled. |
| 65 |
|
| 66 |
- Custom fence formatters are now expected to take a new keyword attribute called `attrs`. `attrs` contains a |
| 67 |
dictionary of key/value pairs defining attributes that should be attached to the main block element generated by a |
| 68 |
given formatter. In general, custom formatters *should* handle these, but are not required to. At the very least, |
| 69 |
they should be updated to take the argument even if they don't do anything with them. Custom fences that do not |
| 70 |
accept this parameter will silently fail. If your custom fence already accepts `**kwargs` (as recommended in the 7.0 |
| 71 |
release), your fence should continue to work even you do not do anything with the attributes. No use and apply the |
| 72 |
new, attributes, you will have to read the `attrs` parameter and set those to one of the elements in your generated |
| 73 |
HTML. |
| 74 |
|
| 75 |
- Custom fence validators have been updated to handle validation of inputs by assigning valid inputs to either an |
| 76 |
`options` dictionary or an `attrs` dictionary. The new function signature looks like this: |
| 77 |
`#!py3 validator(language, inputs, options, attrs, md):`. |
| 78 |
|
| 79 |
- `inputs` contains all the parsed key/value pairs and should **never** be modified. `options` should have inputs |
| 80 |
added to it that configure a formatter's features. You should parse, format and assign all inputs that are |
| 81 |
considered options to the `option` dictionary. |
| 82 |
|
| 83 |
- `attrs` normally would contain copies of any non-option key/value pairs from inputs, unaltered. These would |
| 84 |
usually be applied to HTML elements as attributes. |
| 85 |
|
| 86 |
- `md` is the `Markdown` class instance and is useful if you want to access meta data or anything else in your |
| 87 |
validator. |
| 88 |
|
| 89 |
SuperFences will detect if you are using an older validator and should gracefully transition and use the old |
| 90 |
format, but it is strongly recommended to use the new format. If you run into any issues, you are required to |
| 91 |
update to the new format. In a future version, the graceful transition will be removed. |
| 92 |
|
| 93 |
- Since attributes and options are now parsed via the [`attr_list`][attr-list] extension, custom fences can no longer |
| 94 |
allow inputs in the form `key=` (with no value), they must be in the form `key`, `key="value"` or `key=value`. When |
| 95 |
defining an input in the form `key` (with no value), the value will be the `key` name (this is how |
| 96 |
[`attr_list`][attr-list] handles such cases). To specify an empty `key`, please use `key=""`. |
| 97 |
|
| 98 |
- If a custom validator fails, SuperFences will now gracefully handle the error and try the next custom fence in the |
| 99 |
queue. If a custom formatter fails. If you suspect your custom validator is not working, you should add your own |
| 100 |
debug code to your custom fence to verify whether it is failing or not. |
| 101 |
|
| 102 |
- SuperFences will gracefully handle the error and abort processing the fence. If you suspect your custom formatter is |
| 103 |
not working, you should add your own debug code to your custom fence to verify whether it is failing or not. |
| 104 |
|
| 105 |
## New Extension |
| 106 |
|
| 107 |
[SaneHeaders](../../extensions/saneheaders.md) implements Markdown headers more like CommonMark. Headers require a space |
| 108 |
after the `#` symbol in order for the line to be treated as a header. This allows you to use |
| 109 |
[MagicLink](../../extensions/magiclink.md) issues at the start of a line. See |
| 110 |
[SaneHeaders documentation](../../extensions/saneheaders.md) for more information. |