public static boolean scrollToReference(JEditorPane view, String reference) {
    reference = StringUtil.trimStart(reference, "#");
    List<String> toCheck = Arrays.asList("a", "h1", "h2", "h3", "h4");
    Document document = view.getDocument();
    if (document instanceof HTMLDocument) {
      List<Element> list = new ArrayList<>();
      for (Element root : document.getRootElements()) {
        getAllElements(root, list, toCheck);
      }
      for (Element element : list) {
          AttributeSet attributes = element.getAttributes();
          String nm = (String)attributes.getAttribute(HTML.Attribute.NAME);
          if (nm == null) nm = (String)attributes.getAttribute(HTML.Attribute.ID);
          if ((nm != null) && nm.equals(reference)) {
            try {
              int pos = element.getStartOffset();
              Rectangle r = view.modelToView(pos);
              if (r != null) {
                Rectangle vis = view.getVisibleRect();
                r.y -= 5;
                r.height = vis.height;
                view.scrollRectToVisible(r);
                return true;
              }
            }
            catch (BadLocationException ex) {
              //ignore
            }
          }
      }
    }
    return false;
  }
public static boolean scrollToReference(JEditorPane view, String reference)