Browse Source

Merge pull request #39 from ian-r-rose/cleanup

Cleanup
Ian Rose 6 years ago
parent
commit
5868b22366

+ 3 - 0
packages/toc/src/generators/index.ts

@@ -1,3 +1,6 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
 export * from './markdowndocgenerator';
 export * from './latexgenerator';
 export * from './notebookgenerator';

+ 1 - 1
packages/toc/src/generators/markdowndocgenerator/index.ts

@@ -202,7 +202,7 @@ namespace Private {
     let headingNodes = node.querySelectorAll('h1, h2, h3, h4, h5, h6');
     for (let i = 0; i < headingNodes.length; i++) {
       const heading = headingNodes[i];
-      const level = parseInt(heading.tagName[1]);
+      const level = parseInt(heading.tagName[1], 10);
       let text = heading.textContent ? heading.textContent : '';
       let shallHide = !needsNumbering;
 

+ 3 - 0
packages/toc/src/generators/markdowndocgenerator/optionsmanager.ts

@@ -1,3 +1,6 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
 import { TableOfContentsRegistry } from '../../registry';
 
 import { TableOfContents } from '../../toc';

+ 8 - 5
packages/toc/src/generators/markdowndocgenerator/toolbargenerator.tsx

@@ -1,10 +1,13 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
 import { MarkdownDocGeneratorOptionsManager } from './optionsmanager';
 
 import * as React from 'react';
 
-interface NotebookGeneratorToolbarProps {}
+interface INotebookGeneratorToolbarProps {}
 
-interface NotebookGeneratorToolbarState {
+interface INotebookGeneratorToolbarState {
   numbering: boolean;
 }
 
@@ -13,10 +16,10 @@ export function markdownDocGeneratorToolbar(
 ) {
   // Render the toolbar
   return class extends React.Component<
-    NotebookGeneratorToolbarProps,
-    NotebookGeneratorToolbarState
+    INotebookGeneratorToolbarProps,
+    INotebookGeneratorToolbarState
   > {
-    constructor(props: NotebookGeneratorToolbarProps) {
+    constructor(props: INotebookGeneratorToolbarProps) {
       super(props);
       this.state = { numbering: true };
       options.initializeOptions(true);

+ 10 - 7
packages/toc/src/generators/notebookgenerator/codemirror.tsx

@@ -1,25 +1,28 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
 import * as React from 'react';
 
-import { INotebookHeading } from '../shared';
+import { INotebookHeading } from './heading';
 
-export interface CodeComponentProps {
+export interface ICodeComponentProps {
   heading: INotebookHeading;
 }
 
-export interface CodeComponentState {
+export interface ICodeComponentState {
   heading: INotebookHeading;
 }
 
 export class CodeComponent extends React.Component<
-  CodeComponentProps,
-  CodeComponentState
+  ICodeComponentProps,
+  ICodeComponentState
 > {
-  constructor(props: CodeComponentState) {
+  constructor(props: ICodeComponentProps) {
     super(props);
     this.state = { heading: props.heading };
   }
 
-  componentWillReceiveProps(nextProps: CodeComponentState) {
+  componentWillReceiveProps(nextProps: ICodeComponentProps) {
     this.setState({ heading: nextProps.heading });
   }
 

+ 16 - 0
packages/toc/src/generators/notebookgenerator/heading.ts

@@ -0,0 +1,16 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
+import { Cell } from '@jupyterlab/cells';
+
+import { INumberedHeading } from '../shared';
+
+/**
+ * A heading for a notebook cell.
+ */
+export interface INotebookHeading extends INumberedHeading {
+  type: 'header' | 'markdown' | 'code';
+  prompt?: string;
+  cellRef?: Cell;
+  hasChild?: boolean;
+}

+ 111 - 45
packages/toc/src/generators/notebookgenerator/index.ts

@@ -1,5 +1,6 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
+
 import { ISanitizer } from '@jupyterlab/apputils';
 
 import {
@@ -22,13 +23,12 @@ import { TableOfContents } from '../../toc';
 
 import { NotebookGeneratorOptionsManager } from './optionsmanager';
 
+import { INotebookHeading } from './heading';
+
 import {
   generateNumbering,
-  getMarkdownHeadings,
   isDOM,
   isMarkdown,
-  INotebookHeading,
-  INotebookHeadingTypes,
   sanitizerOptions
 } from '../shared';
 
@@ -68,9 +68,9 @@ export function createNotebookGenerator(
       // determine whether one header has child
       let prevHeading: INotebookHeading | null = null;
       let cellNum = panel.content.widgets.length;
-      for (var i = 0; i <= panel.content.widgets.length; i++) {
+      for (let i = 0; i <= panel.content.widgets.length; i++) {
         let cell: Cell | null = null;
-        if (i != cellNum) {
+        if (i !== cellNum) {
           cell = panel.content.widgets[i];
         }
         let collapsed = false;
@@ -82,7 +82,7 @@ export function createNotebookGenerator(
         if (cell) {
           model = cell.model;
         }
-        if (cell && model && model.type === 'code' && i != cellNum) {
+        if (cell && model && model.type === 'code' && i !== cellNum) {
           // Get the execution count prompt for code cells
           let executionCountNumber = (cell as CodeCell).model
             .executionCount as number;
@@ -185,10 +185,7 @@ export function createNotebookGenerator(
               cell
             );
             let renderedHeading = renderedHeadings[0];
-            if (
-              renderedHeading &&
-              renderedHeading.type === INotebookHeadingTypes.markdown
-            ) {
+            if (renderedHeading && renderedHeading.type === 'markdown') {
               // Do not put the item in TOC if its filtered out by tags
               if (
                 currentCollapseLevel < 0 &&
@@ -199,14 +196,11 @@ export function createNotebookGenerator(
               ) {
                 headings = headings.concat(renderedHeadings);
               }
-            } else if (
-              renderedHeading &&
-              renderedHeading.type === INotebookHeadingTypes.header
-            ) {
+            } else if (renderedHeading && renderedHeading.type === 'header') {
               // Determine whether the heading has children
               if (
                 prevHeading &&
-                prevHeading.type === INotebookHeadingTypes.header &&
+                prevHeading.type === 'header' &&
                 prevHeading.level >= renderedHeading.level
               ) {
                 prevHeading.hasChild = false;
@@ -246,19 +240,19 @@ export function createNotebookGenerator(
               )
             ) {
               if (
-                !(renderedHeading.type === INotebookHeadingTypes.markdown) ||
+                !(renderedHeading.type === 'markdown') ||
                 options.showMarkdown
               ) {
                 prevHeading = renderedHeading;
               }
             }
           }
-        } else if ((model && model.type === 'markdown') || i == cellNum) {
+        } else if ((model && model.type === 'markdown') || i === cellNum) {
           // If the cell is rendered, generate the ToC items from
           // the HTML. If it is not rendered, generate them from
           // the text of the cell.
           if (
-            i == cellNum ||
+            i === cellNum ||
             ((cell as MarkdownCell).rendered &&
               !(cell as MarkdownCell).inputHidden)
           ) {
@@ -289,7 +283,7 @@ export function createNotebookGenerator(
             let lastLevel = Private.getLastLevel(headings);
             let renderedHeadings: INotebookHeading[] = [];
             let renderedHeading: INotebookHeading | null = null;
-            if (i != cellNum) {
+            if (i !== cellNum) {
               renderedHeadings = Private.getRenderedHTMLHeadings(
                 cell!.node,
                 onClickFactory,
@@ -301,10 +295,7 @@ export function createNotebookGenerator(
               );
               renderedHeading = renderedHeadings[0];
             }
-            if (
-              renderedHeading &&
-              renderedHeading.type === INotebookHeadingTypes.markdown
-            ) {
+            if (renderedHeading && renderedHeading.type === 'markdown') {
               // Do not put the item in TOC if its filtered out by tags
               if (
                 currentCollapseLevel < 0 &&
@@ -316,14 +307,13 @@ export function createNotebookGenerator(
                 headings = headings.concat(renderedHeadings);
               }
             } else if (
-              (renderedHeading &&
-                renderedHeading.type === INotebookHeadingTypes.header) ||
+              (renderedHeading && renderedHeading.type === 'header') ||
               !renderedHeading
             ) {
               // Determine whether the heading has children
               if (
                 prevHeading &&
-                prevHeading.type === INotebookHeadingTypes.header &&
+                prevHeading.type === 'header' &&
                 (i === cellNum ||
                   (renderedHeading &&
                     prevHeading.level >= renderedHeading.level))
@@ -366,8 +356,7 @@ export function createNotebookGenerator(
               )
             ) {
               if (
-                (renderedHeading &&
-                  !(renderedHeading.type === INotebookHeadingTypes.markdown)) ||
+                (renderedHeading && !(renderedHeading.type === 'markdown')) ||
                 options.showMarkdown
               ) {
                 prevHeading = renderedHeading;
@@ -400,7 +389,7 @@ export function createNotebookGenerator(
             let renderedHeadings: INotebookHeading[] = [];
             let renderedHeading: INotebookHeading | null = null;
             if (cell) {
-              renderedHeadings = getMarkdownHeadings(
+              renderedHeadings = Private.getMarkdownHeadings(
                 model!.value.text,
                 onClickFactory,
                 numberingDict,
@@ -409,10 +398,7 @@ export function createNotebookGenerator(
               );
               renderedHeading = renderedHeadings[0];
             }
-            if (
-              renderedHeading &&
-              renderedHeading.type === INotebookHeadingTypes.markdown
-            ) {
+            if (renderedHeading && renderedHeading.type === 'markdown') {
               if (
                 renderedHeading &&
                 currentCollapseLevel < 0 &&
@@ -423,14 +409,11 @@ export function createNotebookGenerator(
               ) {
                 headings = headings.concat(renderedHeadings);
               }
-            } else if (
-              renderedHeading &&
-              renderedHeading.type === INotebookHeadingTypes.header
-            ) {
+            } else if (renderedHeading && renderedHeading.type === 'header') {
               // Determine whether the heading has children
               if (
                 prevHeading &&
-                prevHeading.type === INotebookHeadingTypes.header &&
+                prevHeading.type === 'header' &&
                 (i === cellNum || prevHeading.level >= renderedHeading.level)
               ) {
                 prevHeading.hasChild = false;
@@ -491,9 +474,9 @@ namespace Private {
       let cellMetadata = heading.cellRef.model.metadata;
       let cellTagsData = cellMetadata.get('tags') as string[];
       if (cellTagsData) {
-        for (var j = 0; j < cellTagsData.length; j++) {
+        for (let j = 0; j < cellTagsData.length; j++) {
           let name = cellTagsData[j];
-          for (var k = 0; k < tags.length; k++) {
+          for (let k = 0; k < tags.length; k++) {
             if (tags[k] === name) {
               return false;
             }
@@ -510,7 +493,7 @@ namespace Private {
     if (headings.length > 0) {
       let location = headings.length - 1;
       while (location >= 0) {
-        if (headings[location].type === INotebookHeadingTypes.header) {
+        if (headings[location].type === 'header') {
           return headings[location].level;
         }
         location = location - 1;
@@ -547,7 +530,7 @@ namespace Private {
         text: headingText,
         level,
         onClick,
-        type: INotebookHeadingTypes.code,
+        type: 'code',
         prompt: executionCount,
         cellRef: cellRef,
         hasChild: false
@@ -558,6 +541,89 @@ namespace Private {
 }
 
 namespace Private {
+  /**
+   * Given a string of markdown, get the markdown headings
+   * in that string.
+   */
+  export function getMarkdownHeadings(
+    text: string,
+    onClickFactory: (line: number) => (() => void),
+    numberingDict: any,
+    lastLevel: number,
+    cellRef: Cell
+  ): INotebookHeading[] {
+    // Split the text into lines.
+    const lines = text.split('\n');
+    let headings: INotebookHeading[] = [];
+    // Iterate over the lines to get the header level and
+    // the text for the line.
+    let line = lines[0];
+    let idx = 0;
+    // Make an onClick handler for this line.
+    const onClick = onClickFactory(idx);
+
+    // First test for '#'-style headers.
+    let match = line.match(/^([#]{1,6}) (.*)/);
+    let match2 = line.match(/^([=]{2,}|[-]{2,})/);
+    let match3 = line.match(/<h([1-6])>(.*)<\/h\1>/i);
+    if (match) {
+      const level = match[1].length;
+      // Take special care to parse markdown links into raw text.
+      const text = match[2].replace(/\[(.+)\]\(.+\)/g, '$1');
+      let numbering = generateNumbering(numberingDict, level);
+      headings.push({
+        text,
+        level,
+        numbering,
+        onClick,
+        type: 'header',
+        cellRef: cellRef,
+        hasChild: true
+      });
+    } else if (match2 && idx > 0) {
+      // Next test for '==='-style headers.
+      const level = match2[1][0] === '=' ? 1 : 2;
+      // Take special care to parse markdown links into raw text.
+      const text = lines[idx - 1].replace(/\[(.+)\]\(.+\)/g, '$1');
+      let numbering = generateNumbering(numberingDict, level);
+      headings.push({
+        text,
+        level,
+        numbering,
+        onClick,
+        type: 'header',
+        cellRef: cellRef,
+        hasChild: true
+      });
+    } else if (match3) {
+      // Finally test for HTML headers. This will not catch multiline
+      // headers, nor will it catch multiple headers on the same line.
+      // It should do a decent job of catching many, though.
+      const level = parseInt(match3[1], 10);
+      const text = match3[2];
+      let numbering = generateNumbering(numberingDict, level);
+      headings.push({
+        text,
+        level,
+        numbering,
+        onClick,
+        type: 'header',
+        cellRef: cellRef,
+        hasChild: true
+      });
+    } else {
+      headings.push({
+        text: line,
+        level: lastLevel + 1,
+        onClick,
+        type: 'markdown',
+        cellRef: cellRef,
+        hasChild: false
+      });
+    }
+    return headings;
+  }
+
   /**
    * Given an HTML element, generate ToC headings
    * by finding all the headers and making IHeading objects for them.
@@ -587,14 +653,14 @@ namespace Private {
             html: html,
             text: markdownCell.textContent ? markdownCell.textContent : '',
             onClick: onClickFactory(markdownCell),
-            type: INotebookHeadingTypes.markdown,
+            type: 'markdown',
             cellRef: cellRef,
             hasChild: true
           });
         }
       } else {
         const heading = headingNodes[0];
-        const level = parseInt(heading.tagName[1]);
+        const level = parseInt(heading.tagName[1], 10);
         const text = heading.textContent ? heading.textContent : '';
         let shallHide = !needsNumbering;
         if (heading.getElementsByClassName('numbering-entry').length > 0) {
@@ -617,7 +683,7 @@ namespace Private {
           numbering,
           html,
           onClick,
-          type: INotebookHeadingTypes.header,
+          type: 'header',
           cellRef: cellRef,
           hasChild: true
         });

+ 10 - 21
packages/toc/src/generators/notebookgenerator/itemrenderer.tsx

@@ -7,11 +7,9 @@ import { Cell } from '@jupyterlab/cells';
 
 import { NotebookGeneratorOptionsManager } from './optionsmanager';
 
-import {
-  sanitizerOptions,
-  INotebookHeading,
-  INotebookHeadingTypes
-} from '../shared';
+import { INotebookHeading } from './heading';
+
+import { sanitizerOptions } from '../shared';
 
 import * as React from 'react';
 
@@ -20,10 +18,7 @@ export function notebookItemRenderer(
   item: INotebookHeading
 ) {
   let jsx;
-  if (
-    item.type === INotebookHeadingTypes.markdown ||
-    item.type === INotebookHeadingTypes.header
-  ) {
+  if (item.type === 'markdown' || item.type === 'header') {
     const collapseOnClick = (cellRef?: Cell) => {
       let collapsed = cellRef!.model.metadata.get(
         'toc-hr-collapsed'
@@ -34,13 +29,10 @@ export function notebookItemRenderer(
     };
     let fontSizeClass = 'toc-level-size-default';
     let numbering = item.numbering && options.numbering ? item.numbering : '';
-    if (item.type === INotebookHeadingTypes.header) {
+    if (item.type === 'header') {
       fontSizeClass = 'toc-level-size-' + item.level;
     }
-    if (
-      item.html &&
-      (item.type === INotebookHeadingTypes.header || options.showMarkdown)
-    ) {
+    if (item.html && (item.type === 'header' || options.showMarkdown)) {
       jsx = (
         <span
           dangerouslySetInnerHTML={{
@@ -52,7 +44,7 @@ export function notebookItemRenderer(
         />
       );
       // Render the headers
-      if (item.type === INotebookHeadingTypes.header) {
+      if (item.type === 'header') {
         let collapsed = item.cellRef!.model.metadata.get(
           'toc-hr-collapsed'
         ) as boolean;
@@ -94,17 +86,14 @@ export function notebookItemRenderer(
           </div>
         );
       }
-    } else if (
-      item.type === INotebookHeadingTypes.header ||
-      options.showMarkdown
-    ) {
+    } else if (item.type === 'header' || options.showMarkdown) {
       // Render headers/markdown for plain text
       jsx = (
         <span className={item.type + '-cell toc-cell-item ' + fontSizeClass}>
           {numbering + item.text}
         </span>
       );
-      if (item.type === INotebookHeadingTypes.header) {
+      if (item.type === 'header') {
         let collapsed = item.cellRef!.model.metadata.get(
           'toc-hr-collapsed'
         ) as boolean;
@@ -145,7 +134,7 @@ export function notebookItemRenderer(
     } else {
       jsx = null;
     }
-  } else if (item.type === INotebookHeadingTypes.code && options.showCode) {
+  } else if (item.type === 'code' && options.showCode) {
     // Render code cells
     jsx = (
       <div className="toc-code-cell-div">

+ 3 - 0
packages/toc/src/generators/notebookgenerator/optionsmanager.ts

@@ -1,3 +1,6 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
 import { ISanitizer } from '@jupyterlab/apputils';
 
 import { INotebookTracker } from '@jupyterlab/notebook';

+ 11 - 8
packages/toc/src/generators/notebookgenerator/tagstool/index.tsx

@@ -1,16 +1,19 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
 import { INotebookTracker } from '@jupyterlab/notebook';
 import { Cell } from '@jupyterlab/cells';
 import { TagListComponent } from './tagslist';
 import * as React from 'react';
 import { NotebookGeneratorOptionsManager } from '../optionsmanager';
 
-export interface TagsToolComponentProps {
+export interface ITagsToolComponentProps {
   allTagsList: string[];
   tracker: INotebookTracker;
   generatorOptionsRef: NotebookGeneratorOptionsManager;
 }
 
-export interface TagsToolComponentState {
+export interface ITagsToolComponentState {
   selected: string[];
 }
 
@@ -18,10 +21,10 @@ export interface TagsToolComponentState {
 * Create a React component that handles state for the tag dropdown
 */
 export class TagsToolComponent extends React.Component<
-  TagsToolComponentProps,
-  TagsToolComponentState
+  ITagsToolComponentProps,
+  ITagsToolComponentState
 > {
-  constructor(props: TagsToolComponentProps) {
+  constructor(props: ITagsToolComponentProps) {
     super(props);
     this.state = {
       selected: []
@@ -61,9 +64,9 @@ export class TagsToolComponent extends React.Component<
     this.setState({ selected: [] });
   };
 
-  /* 
-  * Check whether a cell is tagged with a certain string
-  */
+  /**
+   * Check whether a cell is tagged with a certain string
+   */
   containsTag(tag: string, cell: Cell) {
     if (cell === null) {
       return false;

+ 6 - 3
packages/toc/src/generators/notebookgenerator/tagstool/tag.tsx

@@ -1,6 +1,9 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
 import * as React from 'react';
 
-export interface TagComponentProps {
+export interface ITagComponentProps {
   selectionStateHandler: (newState: string, add: boolean) => void;
   selectedTags: string[];
   tag: string;
@@ -9,8 +12,8 @@ export interface TagComponentProps {
 /*
 * Create a React component containing one tag label
 */
-export abstract class TagComponent extends React.Component<TagComponentProps> {
-  constructor(props: TagComponentProps) {
+export abstract class TagComponent extends React.Component<ITagComponentProps> {
+  constructor(props: ITagComponentProps) {
     super(props);
   }
 

+ 9 - 6
packages/toc/src/generators/notebookgenerator/tagstool/tagslist.tsx

@@ -1,3 +1,6 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
 import { TagComponent } from './tag';
 
 import * as React from 'react';
@@ -6,7 +9,7 @@ import * as React from 'react';
 * The TagList takes a list of selected tags, a handler to change selection state,
 * and a list of all tags (strings).
 */
-export interface TagListComponentProps {
+export interface ITagListComponentProps {
   selectedTags: string[];
   selectionStateHandler: (newState: string, add: boolean) => void;
   allTagsList: string[] | null;
@@ -15,7 +18,7 @@ export interface TagListComponentProps {
 /*
 * The TagList state contains a list of selected tags
 */
-export interface TagListComponentState {
+export interface ITagListComponentState {
   selected: string[];
 }
 
@@ -23,10 +26,10 @@ export interface TagListComponentState {
 * Create a React component that renders all tags in a list.
 */
 export class TagListComponent extends React.Component<
-  TagListComponentProps,
-  TagListComponentState
+  ITagListComponentProps,
+  ITagListComponentState
 > {
-  constructor(props: TagListComponentProps) {
+  constructor(props: ITagListComponentProps) {
     super(props);
     this.state = { selected: this.props.selectedTags };
   }
@@ -77,7 +80,7 @@ export class TagListComponent extends React.Component<
   */
   render() {
     let allTagsList = this.props.allTagsList;
-    var renderedTagsForAllCells = null;
+    let renderedTagsForAllCells = null;
     if (allTagsList) {
       renderedTagsForAllCells = this.renderElementForTags(allTagsList);
     }

+ 10 - 7
packages/toc/src/generators/notebookgenerator/toolbargenerator.tsx

@@ -1,3 +1,6 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
 import { INotebookTracker } from '@jupyterlab/notebook';
 
 import { NotebookGeneratorOptionsManager } from './optionsmanager';
@@ -6,9 +9,9 @@ import * as React from 'react';
 
 import { TagsToolComponent } from './tagstool';
 
-interface NotebookGeneratorToolbarProps {}
+interface INotebookGeneratorToolbarProps {}
 
-interface NotebookGeneratorToolbarState {
+interface INotebookGeneratorToolbarState {
   showCode: boolean;
   showMarkdown: boolean;
   showTags: boolean;
@@ -21,10 +24,10 @@ export function notebookGeneratorToolbar(
 ) {
   // Render the toolbar
   return class extends React.Component<
-    NotebookGeneratorToolbarProps,
-    NotebookGeneratorToolbarState
+    INotebookGeneratorToolbarProps,
+    INotebookGeneratorToolbarState
   > {
-    constructor(props: NotebookGeneratorToolbarProps) {
+    constructor(props: INotebookGeneratorToolbarProps) {
       super(props);
       this.state = {
         showCode: true,
@@ -115,12 +118,12 @@ export function notebookGeneratorToolbar(
       if (notebook) {
         let cells = notebook.model.cells;
         this.allTags = [];
-        for (var i = 0; i < cells.length; i++) {
+        for (let i = 0; i < cells.length; i++) {
           if (cells.get(i)) {
             let cellMetadata = cells.get(i)!.metadata;
             let cellTagsData = cellMetadata.get('tags') as string[];
             if (cellTagsData) {
-              for (var j = 0; j < cellTagsData.length; j++) {
+              for (let j = 0; j < cellTagsData.length; j++) {
                 let name = cellTagsData[j];
                 this.addTagIntoAllTagsList(name);
               }

+ 5 - 103
packages/toc/src/generators/shared.ts

@@ -1,23 +1,12 @@
-import { Cell } from '@jupyterlab/cells';
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
 import { IHeading } from '../toc';
 
 const VDOM_MIME_TYPE = 'application/vdom.v1+json';
 
 const HTML_MIME_TYPE = 'text/html';
 
-export enum INotebookHeadingTypes {
-  header,
-  markdown,
-  code
-}
-
-export interface INotebookHeading extends INumberedHeading {
-  type: INotebookHeadingTypes;
-  prompt?: string;
-  cellRef?: Cell;
-  hasChild?: boolean;
-}
-
 export interface INumberedHeading extends IHeading {
   numbering?: string | null;
 }
@@ -49,10 +38,10 @@ export function generateNumbering(
   if (numberingDict != null) {
     incrementNumberingDict(numberingDict, level);
     numbering = '';
-    for (var j = 1; j <= level; j++) {
+    for (let j = 1; j <= level; j++) {
       numbering +=
         (numberingDict[j] == undefined ? '0' : numberingDict[j]) + '.';
-      if (j == level) {
+      if (j === level) {
         numbering += ' ';
       }
     }
@@ -60,93 +49,6 @@ export function generateNumbering(
   return numbering;
 }
 
-/**
- * Given a string of markdown, get the markdown headings
- * in that string.
- */
-export function getMarkdownHeadings(
-  text: string,
-  onClickFactory: (line: number) => (() => void),
-  numberingDict: any,
-  lastLevel: number,
-  cellRef: Cell
-): INotebookHeading[] {
-  // Split the text into lines.
-  const lines = text.split('\n');
-  let headings: INotebookHeading[] = [];
-  // Iterate over the lines to get the header level and
-  // the text for the line.
-  let line = lines[0];
-  let idx = 0;
-  // Make an onClick handler for this line.
-  const onClick = onClickFactory(idx);
-
-  // First test for '#'-style headers.
-  let match = line.match(/^([#]{1,6}) (.*)/);
-  let match2 = line.match(/^([=]{2,}|[-]{2,})/);
-  let match3 = line.match(/<h([1-6])>(.*)<\/h\1>/i);
-  if (match) {
-    const level = match[1].length;
-    // Take special care to parse markdown links into raw text.
-    const text = match[2].replace(/\[(.+)\]\(.+\)/g, '$1');
-    let numbering = generateNumbering(numberingDict, level);
-    headings.push({
-      text,
-      level,
-      numbering,
-      onClick,
-      type: INotebookHeadingTypes.header,
-      cellRef: cellRef,
-      hasChild: true
-    });
-  }
-
-  // Next test for '==='-style headers.
-  else if (match2 && idx > 0) {
-    const level = match2[1][0] === '=' ? 1 : 2;
-    // Take special care to parse markdown links into raw text.
-    const text = lines[idx - 1].replace(/\[(.+)\]\(.+\)/g, '$1');
-    let numbering = generateNumbering(numberingDict, level);
-    headings.push({
-      text,
-      level,
-      numbering,
-      onClick,
-      type: INotebookHeadingTypes.header,
-      cellRef: cellRef,
-      hasChild: true
-    });
-  }
-
-  // Finally test for HTML headers. This will not catch multiline
-  // headers, nor will it catch multiple headers on the same line.
-  // It should do a decent job of catching many, though.
-  else if (match3) {
-    const level = parseInt(match3[1], 10);
-    const text = match3[2];
-    let numbering = generateNumbering(numberingDict, level);
-    headings.push({
-      text,
-      level,
-      numbering,
-      onClick,
-      type: INotebookHeadingTypes.header,
-      cellRef: cellRef,
-      hasChild: true
-    });
-  } else {
-    headings.push({
-      text: line,
-      level: lastLevel + 1,
-      onClick,
-      type: INotebookHeadingTypes.markdown,
-      cellRef: cellRef,
-      hasChild: false
-    });
-  }
-  return headings;
-}
-
 /**
  * Return whether the mime type is some flavor of markdown.
  */

+ 1 - 4
packages/toc/src/toc.tsx

@@ -78,10 +78,7 @@ export class TableOfContents extends Widget {
       signal: context.model.contentChanged,
       timeout: RENDER_TIMEOUT
     });
-    this._monitor.activityStopped.connect(
-      this.update,
-      this
-    );
+    this._monitor.activityStopped.connect(this.update, this);
     this.updateTOC();
   }
 

+ 1 - 1
packages/toc/tslint.json

@@ -60,7 +60,7 @@
       "check-whitespace"
     ],
     "one-variable-per-declaration": [true, "ignore-for-loop"],
-    "quotemark": [true, "single", "avoid-escape"],
+    "quotemark": [true, "single", "avoid-escape", "jsx-double"],
     "radix": true,
     "semicolon": [true, "always", "ignore-bound-class-methods"],
     "switch-default": true,