Skip to content

Commit

Permalink
Clanups
Browse files Browse the repository at this point in the history
  • Loading branch information
harshad1 committed May 26, 2024
1 parent 0e1c90e commit dc23d15
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -445,19 +445,22 @@ private String replaceTokens(final String markup, final Map<String, List<String>
return markupReplaced;
}

// Extension to add line numbers to headings
// ---------------------------------------------------------------------------------------------

public static String getIdForLineNumber(final int num) {
return "line-" + num;
}

private static class LineNumberIdProvider implements AttributeProvider {
@Override
public void setAttributes(Node node, AttributablePart part, Attributes attributes) {
if (node instanceof com.vladsch.flexmark.ast.Heading) {
final Document document = node.getDocument();
final int lineNumber = document.getLineNumber(node.getStartOffset());
attributes.addValue("id", "line-" + lineNumber);
attributes.addValue("id", getIdForLineNumber(lineNumber));
}
}

public static AttributeProviderFactory Factory() {
return new LineNumberIdProviderFactory();
}
}

private static class LineNumberIdProviderFactory implements AttributeProviderFactory {
Expand Down Expand Up @@ -486,12 +489,11 @@ public AttributeProvider create(LinkResolverContext context) {
private static class LineNumberIdExtension implements HtmlRenderer.HtmlRendererExtension {
@Override
public void rendererOptions(MutableDataHolder options) {

}

@Override
public void extend(HtmlRenderer.Builder rendererBuilder, String rendererType) {
rendererBuilder.attributeProviderFactory(LineNumberIdProvider.Factory());
rendererBuilder.attributeProviderFactory(new LineNumberIdProviderFactory());
}

public static HtmlRenderer.HtmlRendererExtension create() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -841,9 +841,11 @@ public static void showHeadlineDialog(
dopt.positionCallback = result -> {
final int index = filtered.get(result.get(0));
final int line = headings.get(index).line;

TextViewUtils.selectLines(edit, line);
final String jumpJs = "javascript:document.getElementById('line-" + line + "').scrollIntoView();";
webView.loadUrl(jumpJs);

final String id = MarkdownTextConverter.getIdForLineNumber(line);
webView.loadUrl(String.format("javascript:document.getElementById('%s').scrollIntoView();", id));
};

dopt.neutralButtonText = R.string.filter;
Expand Down

0 comments on commit dc23d15

Please sign in to comment.