Package winterwell.markdown.pagemodel.MarkdownPage

Examples of winterwell.markdown.pagemodel.MarkdownPage.Header


    viewer.setLabelProvider(new LabelProvider() {
      @Override
      public String getText(Object element) {
        if (!(element instanceof MarkdownPage.Header))
          return super.getText(element);
        Header header = ((MarkdownPage.Header) element);
        String hText = header.toString();
        if (!showWordCounts)
          return hText;
        IRegion region = getRegion(header);
        String text;
        try {
View Full Code Here


   * @param endParent
   */
  private void updateSectionFoldingAnnotations2(IDocument doc, List<Header> headers,
      Map<Annotation, Position> newAnnotations, int endParent) {
    for (int i=0; i<headers.size(); i++) {
      Header header = headers.get(i);
      ProjectionAnnotation annotation = new ProjectionAnnotation();
      try {
        int line = header.getLineNumber();
        int start = doc.getLineOffset(line);
        int end = (i==headers.size()-1)? endParent
            : doc.getLineOffset(headers.get(i+1).getLineNumber());
        Position position = new Position(start, end-start);
        newAnnotations.put(annotation, position);
        // Recurse
        List<Header> subHeaders = header.getSubHeaders();
        if (subHeaders.size() > 0) {
          updateSectionFoldingAnnotations2(doc, subHeaders, newAnnotations, end);
        }
      } catch (Exception ex) {
        System.out.println(ex);
View Full Code Here

    for(; line>-1; line--) {
      KLineType lt = lineTypes.get(line);
      if (lt.toString().startsWith("H")) break;
    }
    if (line<0) return;
    Header header = (Header) page.getPageObject(line);
    // Set
    IStructuredSelection selection = new StructuredSelection(header);
    viewer.setSelection(selection , true);
  }
View Full Code Here

    int end = r.getOffset() + r.getLength();
    int length = end - start;
    // Get new insertion point
    int insert;
    if (i==1) {
      Header nextSection = last.getNext();
      if (nextSection==null) return;
      IRegion nr = getRegion(nextSection);
      insert = nr.getOffset()+nr.getLength();
    } else {
      Header prevSection = first.getPrevious();
      if (prevSection==null) return;
      IRegion nr = getRegion(prevSection);
      insert = nr.getOffset();
    }
    // Get text
View Full Code Here

    HashSet<Header> adjusted = new HashSet<Header>();
    // Adjust
    MarkdownPage mdPage = fTextEditor.getMarkdownPage();
    List<String> lines = new ArrayList<String>(mdPage.getText());
    while(toAdjust.size() != 0) {
      Header h = toAdjust.iterator().next();
      toAdjust.remove(h);
      adjusted.add(h);
      String line = lines.get(h.getLineNumber());
      if (upDown==-1) {
        if (h.getLevel() == 1) return; // Level 1; can't promote
        if (line.startsWith("##")) line = line.substring(1);
        else {
          return; // TODO support for ------ / ========
        }
      } else line = "#" + line;
      int ln = h.getLineNumber();
      lines.set(ln, line);
      // kids
      ArrayList<Header> kids = new ArrayList<Header>(h.getSubHeaders());
      for (Header header : kids) {
        if ( ! adjusted.contains(header)) toAdjust.add(header);
      }
    }
    // Set
View Full Code Here

  protected IRegion getRegion(Header header) {
    try {
      IDocument doc = fTextEditor.getDocument();
      // Line numbers
      int start = header.getLineNumber();
      Header next = header.getNext();
      int end;
      if (next != null) {
        end = next.getLineNumber() - 1;
      } else {
        end = doc.getNumberOfLines() - 1;
      }
      int offset = doc.getLineOffset(start);
      IRegion ei = doc.getLineInformation(end);
View Full Code Here

    // problem caused by a line beginning --, now fixed
    String txt = FileUtils.read(new File(
        "/home/daniel/winterwell/companies/DTC/projects/DTC-bayes/report1.txt"));
    MarkdownPage p = new MarkdownPage(txt);
    List<Header> h1s = p.getHeadings(null);
    Header h1 = h1s.get(0);
    List<Header> h2s = h1.getSubHeaders();
    assert h2s.size() > 2;
  }
View Full Code Here

TOP

Related Classes of winterwell.markdown.pagemodel.MarkdownPage.Header

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.