| 105 | 105 | */ |
| 106 | 106 | private static void update( final String message ) { |
| 107 | try { | |
| 108 | throw new RuntimeException(); | |
| 109 | } catch( final Exception e ) { | |
| 110 | e.printStackTrace(); | |
| 111 | } | |
| 112 | ||
| 113 | 107 | runLater( |
| 114 | 108 | () -> { |
| 28 | 28 | package com.keenwrite.processors.markdown; |
| 29 | 29 | |
| 30 | import com.keenwrite.Constants; | |
| 30 | 31 | import com.vladsch.flexmark.html.AttributeProvider; |
| 31 | 32 | import com.vladsch.flexmark.html.AttributeProviderFactory; |
| ... | ||
| 51 | 52 | /** |
| 52 | 53 | * Responsible for creating the id attribute. This class is instantiated |
| 53 | * each time the document is rendered, thereby resetting the count to zero. | |
| 54 | * once: for the HTML element containing the {@link Constants#CARET_ID}. | |
| 54 | 55 | */ |
| 55 | 56 | public static class IdAttributeProvider implements AttributeProvider { |
| ... | ||
| 85 | 86 | if( mCaret.isBetweenText( began, ended ) || |
| 86 | 87 | prev != null && mCaret.isBetweenText( prev.getEndOffset(), began ) ) { |
| 88 | ||
| 89 | // This magic line enables synchronizing the text editor with preview. | |
| 87 | 90 | attributes.addValue( AttributeImpl.of( "id", CARET_ID ) ); |
| 88 | 91 | } |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | /** | |
| 51 | * Used for building a new {@link CaretPosition} instance. | |
| 52 | */ | |
| 50 | 53 | public static class Mutator { |
| 51 | 54 | /** |
| 52 | 55 | * Caret's current paragraph index (i.e., current caret line number). |
| 53 | 56 | */ |
| 54 | 57 | private ObservableValue<Integer> mParagraph; |
| 55 | 58 | |
| 59 | /** | |
| 60 | * Used to count the number of lines in the text editor document. | |
| 61 | */ | |
| 56 | 62 | private LiveList<Paragraph<Collection<String>, String, |
| 57 | 63 | Collection<String>>> mParagraphs; |
| ... | ||
| 135 | 141 | } |
| 136 | 142 | |
| 143 | /** | |
| 144 | * Returns the number of lines in the text editor. | |
| 145 | * | |
| 146 | * @return The size of the text editor's paragraph list plus one. | |
| 147 | */ | |
| 137 | 148 | private int getParagraphCount() { |
| 138 | 149 | return mMutator.mParagraphs.size() + 1; |
| 139 | 150 | } |
| 140 | 151 | |
| 152 | /** | |
| 153 | * Returns the absolute position of the caret within the entire document. | |
| 154 | * | |
| 155 | * @return A zero-based index of the caret position. | |
| 156 | */ | |
| 141 | 157 | private int getTextOffset() { |
| 142 | 158 | return mMutator.mTextOffset.getValue(); |
| 143 | 159 | } |
| 144 | 160 | |
| 161 | /** | |
| 162 | * Returns the position of the caret within the current paragraph being | |
| 163 | * edited. | |
| 164 | * | |
| 165 | * @return A zero-based index of the caret position relative to the | |
| 166 | * current paragraph. | |
| 167 | */ | |
| 145 | 168 | private int getParaOffset() { |
| 146 | 169 | return mMutator.mParaOffset.getValue(); |
| 119 | 119 | |
| 120 | 120 | /** |
| 121 | * Creates an extension capable of handling delimited TeX code in Markdown. | |
| 121 | * Creates an extension capable of intercepting R code blocks and preventing | |
| 122 | * them from being converted into HTML {@code <code>} elements. | |
| 122 | 123 | */ |
| 123 | 124 | public static RExtension create() { |