@jupyterlab/cells 3.4.1 → 4.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/widget.d.ts CHANGED
@@ -3,8 +3,9 @@ import { IChangedArgs } from '@jupyterlab/coreutils';
3
3
  import { CodeEditor, CodeEditorWrapper } from '@jupyterlab/codeeditor';
4
4
  import { IObservableJSON, IObservableMap } from '@jupyterlab/observables';
5
5
  import { IOutputPrompt, IStdin, OutputArea, Stdin } from '@jupyterlab/outputarea';
6
- import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
6
+ import { IRenderMime, IRenderMimeRegistry } from '@jupyterlab/rendermime';
7
7
  import { KernelMessage } from '@jupyterlab/services';
8
+ import { ITranslator } from '@jupyterlab/translation';
8
9
  import { JSONObject, JSONValue, PartialJSONValue } from '@lumino/coreutils';
9
10
  import { Message } from '@lumino/messaging';
10
11
  import { ISignal, Signal } from '@lumino/signaling';
@@ -12,7 +13,6 @@ import { Widget } from '@lumino/widgets';
12
13
  import { ICellFooter, ICellHeader } from './headerfooter';
13
14
  import { IInputPrompt, InputArea } from './inputarea';
14
15
  import { IAttachmentsCellModel, ICellModel, ICodeCellModel, IMarkdownCellModel, IRawCellModel } from './model';
15
- export declare const MARKDOWN_HEADING_COLLAPSED = "jp-MarkdownHeadingCollapsed";
16
16
  /** ****************************************************************************
17
17
  * Cell
18
18
  ******************************************************************************/
@@ -65,6 +65,10 @@ export declare class Cell<T extends ICellModel = ICellModel> extends Widget {
65
65
  */
66
66
  get readOnly(): boolean;
67
67
  set readOnly(value: boolean);
68
+ /**
69
+ * Whether the cell is a placeholder that differ rendering
70
+ */
71
+ isPlaceholder(): boolean;
68
72
  /**
69
73
  * Save view editable state to model
70
74
  */
@@ -145,6 +149,7 @@ export declare class Cell<T extends ICellModel = ICellModel> extends Widget {
145
149
  * Handle changes in the metadata.
146
150
  */
147
151
  protected onMetadataChanged(model: IObservableJSON, args: IObservableMap.IChangedArgs<PartialJSONValue | undefined>): void;
152
+ protected translator: ITranslator;
148
153
  protected _displayChanged: Signal<this, void>;
149
154
  private _readOnly;
150
155
  private _model;
@@ -152,6 +157,7 @@ export declare class Cell<T extends ICellModel = ICellModel> extends Widget {
152
157
  private _input;
153
158
  private _inputWrapper;
154
159
  private _inputPlaceholder;
160
+ private _isPlaceholder;
155
161
  private _syncCollapse;
156
162
  private _syncEditable;
157
163
  private _resizeDebouncer;
@@ -188,6 +194,10 @@ export declare namespace Cell {
188
194
  * Whether this cell is a placeholder for future rendering.
189
195
  */
190
196
  placeholder?: boolean;
197
+ /**
198
+ * The application language translator.
199
+ */
200
+ translator?: ITranslator;
191
201
  }
192
202
  /**
193
203
  * The factory object for customizable cell children.
@@ -227,7 +237,7 @@ export declare namespace Cell {
227
237
  */
228
238
  createCellHeader(): ICellHeader;
229
239
  /**
230
- * Create a new cell header for the parent widget.
240
+ * Create a new cell footer for the parent widget.
231
241
  */
232
242
  createCellFooter(): ICellFooter;
233
243
  /**
@@ -463,26 +473,47 @@ export declare class MarkdownCell extends AttachmentsCell<IMarkdownCellModel> {
463
473
  */
464
474
  get ready(): Promise<void>;
465
475
  /**
466
- * Text that represents the heading if cell is a heading.
476
+ * Text that represents the highest heading (i.e. lowest level) if cell is a heading.
467
477
  * Returns empty string if not a heading.
468
478
  */
469
479
  get headingInfo(): {
470
480
  text: string;
471
481
  level: number;
472
482
  };
483
+ /**
484
+ * Whether the heading is collapsed or not.
485
+ */
473
486
  get headingCollapsed(): boolean;
474
487
  set headingCollapsed(value: boolean);
488
+ /**
489
+ * Number of collapsed sub cells.
490
+ */
475
491
  get numberChildNodes(): number;
476
492
  set numberChildNodes(value: number);
477
- get toggleCollapsedSignal(): Signal<this, boolean>;
493
+ /**
494
+ * Signal emitted when the cell collapsed state changes.
495
+ */
496
+ get headingCollapsedChanged(): ISignal<MarkdownCell, boolean>;
478
497
  /**
479
498
  * Whether the cell is rendered.
480
499
  */
481
500
  get rendered(): boolean;
482
501
  set rendered(value: boolean);
502
+ /**
503
+ * Signal emitted when the markdown cell rendered state changes
504
+ */
505
+ get renderedChanged(): ISignal<MarkdownCell, boolean>;
483
506
  get showEditorForReadOnly(): boolean;
484
507
  set showEditorForReadOnly(value: boolean);
508
+ /**
509
+ * Renderer
510
+ */
511
+ get renderer(): IRenderMime.IRenderer;
485
512
  protected maybeCreateCollapseButton(): void;
513
+ /**
514
+ * Create, update or remove the hidden cells button.
515
+ * Note that the actual visibility is controlled in Static Notebook by toggling jp-mod-showHiddenCellsButton class.
516
+ */
486
517
  protected maybeCreateOrUpdateExpandButton(): void;
487
518
  /**
488
519
  * Render the collapse button for heading cells,
@@ -518,10 +549,11 @@ export declare class MarkdownCell extends AttachmentsCell<IMarkdownCellModel> {
518
549
  private _monitor;
519
550
  private _numberChildNodes;
520
551
  private _headingCollapsed;
521
- private _toggleCollapsedSignal;
552
+ private _headingCollapsedChanged;
522
553
  private _renderer;
523
554
  private _rendermime;
524
555
  private _rendered;
556
+ private _renderedChanged;
525
557
  private _prevText;
526
558
  private _ready;
527
559
  private _showEditorForReadOnlyMarkdown;
package/lib/widget.js CHANGED
@@ -2,11 +2,12 @@
2
2
  | Copyright (c) Jupyter Development Team.
3
3
  | Distributed under the terms of the Modified BSD License.
4
4
  |----------------------------------------------------------------------------*/
5
- import marked from 'marked';
6
5
  import { AttachmentsResolver } from '@jupyterlab/attachments';
7
6
  import { ActivityMonitor, URLExt } from '@jupyterlab/coreutils';
8
7
  import { OutputArea, OutputPrompt, SimplifiedOutputArea, Stdin } from '@jupyterlab/outputarea';
9
8
  import { imageRendererFactory, MimeModel } from '@jupyterlab/rendermime';
9
+ import { TableOfContentsUtils } from '@jupyterlab/toc';
10
+ import { nullTranslator } from '@jupyterlab/translation';
10
11
  import { addIcon } from '@jupyterlab/ui-components';
11
12
  import { PromiseDelegate, UUID } from '@lumino/coreutils';
12
13
  import { filter, some, toArray } from '@lumino/algorithm';
@@ -74,7 +75,7 @@ const MARKDOWN_CELL_CLASS = 'jp-MarkdownCell';
74
75
  * The class name added to rendered markdown output widgets.
75
76
  */
76
77
  const MARKDOWN_OUTPUT_CLASS = 'jp-MarkdownOutput';
77
- export const MARKDOWN_HEADING_COLLAPSED = 'jp-MarkdownHeadingCollapsed';
78
+ const MARKDOWN_HEADING_COLLAPSED = 'jp-MarkdownHeadingCollapsed';
78
79
  const HEADING_COLLAPSER_CLASS = 'jp-collapseHeadingButton';
79
80
  const SHOW_HIDDEN_CELLS_CLASS = 'jp-showHiddenCellsButton';
80
81
  /**
@@ -109,10 +110,12 @@ export class Cell extends Widget {
109
110
  * Construct a new base cell widget.
110
111
  */
111
112
  constructor(options) {
113
+ var _a;
112
114
  super();
113
115
  this._displayChanged = new Signal(this);
114
116
  this._readOnly = false;
115
117
  this._inputHidden = false;
118
+ this._isPlaceholder = false;
116
119
  this._syncCollapse = false;
117
120
  this._syncEditable = false;
118
121
  this._resizeDebouncer = new Debouncer(() => {
@@ -123,6 +126,8 @@ export class Cell extends Widget {
123
126
  const contentFactory = (this.contentFactory =
124
127
  options.contentFactory || Cell.defaultContentFactory);
125
128
  this.layout = new PanelLayout();
129
+ // Set up translator for aria labels
130
+ this.translator = options.translator || nullTranslator;
126
131
  // Header
127
132
  const header = contentFactory.createCellHeader();
128
133
  header.addClass(CELL_HEADER_CLASS);
@@ -149,6 +154,7 @@ export class Cell extends Widget {
149
154
  const footer = this.contentFactory.createCellFooter();
150
155
  footer.addClass(CELL_FOOTER_CLASS);
151
156
  this.layout.addWidget(footer);
157
+ this._isPlaceholder = (_a = options.placeholder) !== null && _a !== void 0 ? _a : false;
152
158
  // Editor settings
153
159
  if (options.editorConfig) {
154
160
  this.editor.setOptions(Object.assign({}, options.editorConfig));
@@ -225,6 +231,12 @@ export class Cell extends Widget {
225
231
  }
226
232
  this.update();
227
233
  }
234
+ /**
235
+ * Whether the cell is a placeholder that differ rendering
236
+ */
237
+ isPlaceholder() {
238
+ return this._isPlaceholder;
239
+ }
228
240
  /**
229
241
  * Save view editable state to model
230
242
  */
@@ -363,7 +375,8 @@ export class Cell extends Widget {
363
375
  return new constructor({
364
376
  model: this.model,
365
377
  contentFactory: this.contentFactory,
366
- placeholder: false
378
+ placeholder: false,
379
+ translator: this.translator
367
380
  });
368
381
  }
369
382
  /**
@@ -468,7 +481,7 @@ export class Cell extends Widget {
468
481
  return new CellHeader();
469
482
  }
470
483
  /**
471
- * Create a new cell header for the parent widget.
484
+ * Create a new cell footer for the parent widget.
472
485
  */
473
486
  createCellFooter() {
474
487
  return new CellFooter();
@@ -514,10 +527,16 @@ export class CodeCell extends Cell {
514
527
  this._syncScrolled = false;
515
528
  this._savingMetadata = false;
516
529
  this.addClass(CODE_CELL_CLASS);
530
+ const trans = this.translator.load('jupyterlab');
517
531
  // Only save options not handled by parent constructor.
518
532
  const rendermime = (this._rendermime = options.rendermime);
519
533
  const contentFactory = this.contentFactory;
520
534
  const model = this.model;
535
+ // Note that modifying the below label warrants one to also modify
536
+ // the same in this._outputLengthHandler. Ideally, this label must
537
+ // have been a constant and used in both places but it is not done
538
+ // so because of limitations in the translation manager.
539
+ let ariaLabel = trans.__('Code Cell Content with Output');
521
540
  if (!options.placeholder) {
522
541
  // Insert the output before the cell footer.
523
542
  const outputWrapper = (this._outputWrapper = new Panel());
@@ -536,6 +555,7 @@ export class CodeCell extends Cell {
536
555
  // if there are no outputs.
537
556
  if (model.outputs.length === 0) {
538
557
  this.addClass(NO_OUTPUTS_CLASS);
558
+ ariaLabel = trans.__('Code Cell Content');
539
559
  }
540
560
  output.outputLengthChanged.connect(this._outputLengthHandler, this);
541
561
  outputWrapper.addWidget(outputCollapser);
@@ -550,6 +570,7 @@ export class CodeCell extends Cell {
550
570
  });
551
571
  }
552
572
  model.stateChanged.connect(this.onStateChanged, this);
573
+ this.node.setAttribute('aria-label', ariaLabel);
553
574
  }
554
575
  /**
555
576
  * Initialize view state from model.
@@ -724,7 +745,8 @@ export class CodeCell extends Cell {
724
745
  model: this.model,
725
746
  contentFactory: this.contentFactory,
726
747
  rendermime: this._rendermime,
727
- placeholder: false
748
+ placeholder: false,
749
+ translator: this.translator
728
750
  });
729
751
  }
730
752
  /**
@@ -801,6 +823,11 @@ export class CodeCell extends Cell {
801
823
  _outputLengthHandler(sender, args) {
802
824
  const force = args === 0 ? true : false;
803
825
  this.toggleClass(NO_OUTPUTS_CLASS, force);
826
+ const trans = this.translator.load('jupyterlab');
827
+ const ariaLabel = force
828
+ ? trans.__('Code Cell Content')
829
+ : trans.__('Code Cell Content with Output');
830
+ this.node.setAttribute('aria-label', ariaLabel);
804
831
  }
805
832
  }
806
833
  /**
@@ -1115,13 +1142,15 @@ export class MarkdownCell extends AttachmentsCell {
1115
1142
  constructor(options) {
1116
1143
  var _a, _b, _c;
1117
1144
  super(options);
1118
- this._toggleCollapsedSignal = new Signal(this);
1119
- this._renderer = null;
1145
+ this._headingCollapsedChanged = new Signal(this);
1120
1146
  this._rendered = true;
1147
+ this._renderedChanged = new Signal(this);
1121
1148
  this._prevText = '';
1122
1149
  this._ready = new PromiseDelegate();
1123
1150
  this._showEditorForReadOnlyMarkdown = true;
1124
1151
  this.addClass(MARKDOWN_CELL_CLASS);
1152
+ const trans = this.translator.load('jupyterlab');
1153
+ this.node.setAttribute('aria-label', trans.__('Markdown Cell Content'));
1125
1154
  // Ensure we can resolve attachments:
1126
1155
  this._rendermime = options.rendermime.clone({
1127
1156
  resolver: new AttachmentsResolver({
@@ -1129,6 +1158,8 @@ export class MarkdownCell extends AttachmentsCell {
1129
1158
  model: this.model.attachments
1130
1159
  })
1131
1160
  });
1161
+ this._renderer = this._rendermime.createRenderer('text/markdown');
1162
+ this._renderer.addClass(MARKDOWN_OUTPUT_CLASS);
1132
1163
  // Stop codemirror handling paste
1133
1164
  this.editor.setOption('handlePaste', false);
1134
1165
  // Check if heading cell is set to be collapsed
@@ -1148,7 +1179,8 @@ export class MarkdownCell extends AttachmentsCell {
1148
1179
  });
1149
1180
  this.renderCollapseButtons(this._renderer);
1150
1181
  this.renderInput(this._renderer);
1151
- this._showEditorForReadOnlyMarkdown = (_c = options.showEditorForReadOnlyMarkdown) !== null && _c !== void 0 ? _c : MarkdownCell.defaultShowEditorForReadOnlyMarkdown;
1182
+ this._showEditorForReadOnlyMarkdown =
1183
+ (_c = options.showEditorForReadOnlyMarkdown) !== null && _c !== void 0 ? _c : MarkdownCell.defaultShowEditorForReadOnlyMarkdown;
1152
1184
  }
1153
1185
  /**
1154
1186
  * A promise that resolves when the widget renders for the first time.
@@ -1157,49 +1189,55 @@ export class MarkdownCell extends AttachmentsCell {
1157
1189
  return this._ready.promise;
1158
1190
  }
1159
1191
  /**
1160
- * Text that represents the heading if cell is a heading.
1192
+ * Text that represents the highest heading (i.e. lowest level) if cell is a heading.
1161
1193
  * Returns empty string if not a heading.
1162
1194
  */
1163
1195
  get headingInfo() {
1164
- let text = this.model.value.text;
1165
- const lines = marked.lexer(text);
1166
- let line;
1167
- for (line of lines) {
1168
- if (line.type === 'heading') {
1169
- return { text: line.text, level: line.depth };
1170
- }
1171
- else if (line.type === 'html') {
1172
- let match = line.raw.match(/<h([1-6])(.*?)>(.*?)<\/h\1>/);
1173
- if (match === null || match === void 0 ? void 0 : match[3]) {
1174
- return { text: match[3], level: parseInt(match[1]) };
1175
- }
1176
- return { text: '', level: -1 };
1177
- }
1196
+ // Use table of content algorithm for consistency
1197
+ const headings = TableOfContentsUtils.Markdown.getHeadings(this.model.value.text, {
1198
+ maximalDepth: 6,
1199
+ numberHeaders: false
1200
+ });
1201
+ if (headings.length > 0) {
1202
+ // Return the highest level
1203
+ const { text, level } = headings.reduce((prev, curr) => (prev.level <= curr.level ? prev : curr), headings[0]);
1204
+ return { text, level };
1205
+ }
1206
+ else {
1207
+ return { text: '', level: -1 };
1178
1208
  }
1179
- return { text: '', level: -1 };
1180
1209
  }
1210
+ /**
1211
+ * Whether the heading is collapsed or not.
1212
+ */
1181
1213
  get headingCollapsed() {
1182
1214
  return this._headingCollapsed;
1183
1215
  }
1184
1216
  set headingCollapsed(value) {
1185
- this._headingCollapsed = value;
1186
- if (value) {
1187
- this.model.metadata.set(MARKDOWN_HEADING_COLLAPSED, value);
1188
- }
1189
- else if (this.model.metadata.has(MARKDOWN_HEADING_COLLAPSED)) {
1190
- this.model.metadata.delete(MARKDOWN_HEADING_COLLAPSED);
1191
- }
1192
- const collapseButton = this.inputArea.promptNode.getElementsByClassName(HEADING_COLLAPSER_CLASS)[0];
1193
- if (collapseButton) {
1217
+ if (this._headingCollapsed !== value) {
1218
+ this._headingCollapsed = value;
1194
1219
  if (value) {
1195
- collapseButton.classList.add('jp-mod-collapsed');
1220
+ this.model.metadata.set(MARKDOWN_HEADING_COLLAPSED, value);
1196
1221
  }
1197
- else {
1198
- collapseButton.classList.remove('jp-mod-collapsed');
1222
+ else if (this.model.metadata.has(MARKDOWN_HEADING_COLLAPSED)) {
1223
+ this.model.metadata.delete(MARKDOWN_HEADING_COLLAPSED);
1224
+ }
1225
+ const collapseButton = this.inputArea.promptNode.getElementsByClassName(HEADING_COLLAPSER_CLASS)[0];
1226
+ if (collapseButton) {
1227
+ if (value) {
1228
+ collapseButton.classList.add('jp-mod-collapsed');
1229
+ }
1230
+ else {
1231
+ collapseButton.classList.remove('jp-mod-collapsed');
1232
+ }
1199
1233
  }
1234
+ this.renderCollapseButtons(this._renderer);
1235
+ this._headingCollapsedChanged.emit(this._headingCollapsed);
1200
1236
  }
1201
- this.renderCollapseButtons(this._renderer);
1202
1237
  }
1238
+ /**
1239
+ * Number of collapsed sub cells.
1240
+ */
1203
1241
  get numberChildNodes() {
1204
1242
  return this._numberChildNodes;
1205
1243
  }
@@ -1207,8 +1245,11 @@ export class MarkdownCell extends AttachmentsCell {
1207
1245
  this._numberChildNodes = value;
1208
1246
  this.renderCollapseButtons(this._renderer);
1209
1247
  }
1210
- get toggleCollapsedSignal() {
1211
- return this._toggleCollapsedSignal;
1248
+ /**
1249
+ * Signal emitted when the cell collapsed state changes.
1250
+ */
1251
+ get headingCollapsedChanged() {
1252
+ return this._headingCollapsedChanged;
1212
1253
  }
1213
1254
  /**
1214
1255
  * Whether the cell is rendered.
@@ -1234,6 +1275,13 @@ export class MarkdownCell extends AttachmentsCell {
1234
1275
  }
1235
1276
  // If the rendered state changed, raise an event.
1236
1277
  this._displayChanged.emit();
1278
+ this._renderedChanged.emit(this._rendered);
1279
+ }
1280
+ /**
1281
+ * Signal emitted when the markdown cell rendered state changes
1282
+ */
1283
+ get renderedChanged() {
1284
+ return this._renderedChanged;
1237
1285
  }
1238
1286
  /*
1239
1287
  * Whether the Markdown editor is visible in read-only mode.
@@ -1247,6 +1295,12 @@ export class MarkdownCell extends AttachmentsCell {
1247
1295
  this.rendered = true;
1248
1296
  }
1249
1297
  }
1298
+ /**
1299
+ * Renderer
1300
+ */
1301
+ get renderer() {
1302
+ return this._renderer;
1303
+ }
1250
1304
  maybeCreateCollapseButton() {
1251
1305
  if (this.headingInfo.level > 0 &&
1252
1306
  this.inputArea.promptNode.getElementsByClassName(HEADING_COLLAPSER_CLASS)
@@ -1262,39 +1316,42 @@ export class MarkdownCell extends AttachmentsCell {
1262
1316
  }
1263
1317
  collapseButton.onclick = (event) => {
1264
1318
  this.headingCollapsed = !this.headingCollapsed;
1265
- this._toggleCollapsedSignal.emit(this._headingCollapsed);
1266
1319
  };
1267
1320
  }
1268
1321
  }
1322
+ /**
1323
+ * Create, update or remove the hidden cells button.
1324
+ * Note that the actual visibility is controlled in Static Notebook by toggling jp-mod-showHiddenCellsButton class.
1325
+ */
1269
1326
  maybeCreateOrUpdateExpandButton() {
1270
- var _a, _b;
1271
- const expandButton = this.node.getElementsByClassName(SHOW_HIDDEN_CELLS_CLASS);
1272
- // Create the "show hidden" button if not already created
1273
- if (this.headingCollapsed &&
1274
- expandButton.length === 0 &&
1275
- this._numberChildNodes > 0) {
1276
- const numberChildNodes = document.createElement('button');
1277
- numberChildNodes.className = `bp3-button bp3-minimal jp-Button ${SHOW_HIDDEN_CELLS_CLASS}`;
1278
- addIcon.render(numberChildNodes);
1279
- const numberChildNodesText = document.createElement('div');
1280
- numberChildNodesText.nodeValue = `${this._numberChildNodes} cell${this._numberChildNodes > 1 ? 's' : ''} hidden`;
1281
- numberChildNodes.appendChild(numberChildNodesText);
1282
- numberChildNodes.onclick = () => {
1327
+ const showHiddenCellsButtonList = this.node.getElementsByClassName(SHOW_HIDDEN_CELLS_CLASS);
1328
+ let trans = this.translator.load('jupyterlab');
1329
+ let buttonText = trans._n('%1 cell hidden', '%1 cells hidden', this._numberChildNodes);
1330
+ let needToCreateButton = this.headingCollapsed &&
1331
+ this._numberChildNodes > 0 &&
1332
+ showHiddenCellsButtonList.length == 0;
1333
+ if (needToCreateButton) {
1334
+ const newShowHiddenCellsButton = document.createElement('button');
1335
+ newShowHiddenCellsButton.className = `jp-mod-minimal jp-Button ${SHOW_HIDDEN_CELLS_CLASS}`;
1336
+ addIcon.render(newShowHiddenCellsButton);
1337
+ const buttonTextElement = document.createElement('div');
1338
+ buttonTextElement.textContent = buttonText;
1339
+ newShowHiddenCellsButton.appendChild(buttonTextElement);
1340
+ newShowHiddenCellsButton.onclick = () => {
1283
1341
  this.headingCollapsed = false;
1284
- this._toggleCollapsedSignal.emit(this._headingCollapsed);
1285
1342
  };
1286
- this.node.appendChild(numberChildNodes);
1287
- }
1288
- else if (((_b = (_a = expandButton === null || expandButton === void 0 ? void 0 : expandButton[0]) === null || _a === void 0 ? void 0 : _a.childNodes) === null || _b === void 0 ? void 0 : _b.length) > 1) {
1289
- // If the heading is collapsed, update text
1290
- if (this._headingCollapsed) {
1291
- expandButton[0].childNodes[1].textContent = `${this._numberChildNodes} cell${this._numberChildNodes > 1 ? 's' : ''} hidden`;
1292
- // If the heading isn't collapsed, remove the button
1293
- }
1294
- else {
1295
- for (const el of expandButton) {
1296
- this.node.removeChild(el);
1297
- }
1343
+ this.node.appendChild(newShowHiddenCellsButton);
1344
+ }
1345
+ let needToUpdateButtonText = this.headingCollapsed &&
1346
+ this._numberChildNodes > 0 &&
1347
+ showHiddenCellsButtonList.length == 1;
1348
+ if (needToUpdateButtonText) {
1349
+ showHiddenCellsButtonList[0].childNodes[1].textContent = buttonText;
1350
+ }
1351
+ let needToRemoveButton = !(this.headingCollapsed && this._numberChildNodes > 0);
1352
+ if (needToRemoveButton) {
1353
+ for (const button of showHiddenCellsButtonList) {
1354
+ this.node.removeChild(button);
1298
1355
  }
1299
1356
  }
1300
1357
  }
@@ -1322,6 +1379,15 @@ export class MarkdownCell extends AttachmentsCell {
1322
1379
  showEditor() {
1323
1380
  this.removeClass(RENDERED_CLASS);
1324
1381
  this.inputArea.showEditor();
1382
+ // if this is going to be a heading, place the cursor accordingly
1383
+ let numHashAtStart = (this.model.value.text.match(/^#+/g) || [''])[0]
1384
+ .length;
1385
+ if (numHashAtStart > 0) {
1386
+ this.inputArea.editor.setCursorPosition({
1387
+ column: numHashAtStart + 1,
1388
+ line: 0
1389
+ });
1390
+ }
1325
1391
  }
1326
1392
  /*
1327
1393
  * Handle `update-request` messages.
@@ -1362,14 +1428,10 @@ export class MarkdownCell extends AttachmentsCell {
1362
1428
  // Do not re-render if the text has not changed.
1363
1429
  if (text !== this._prevText) {
1364
1430
  const mimeModel = new MimeModel({ data: { 'text/markdown': text } });
1365
- if (!this._renderer) {
1366
- this._renderer = this._rendermime.createRenderer('text/markdown');
1367
- this._renderer.addClass(MARKDOWN_OUTPUT_CLASS);
1368
- }
1369
1431
  this._prevText = text;
1370
1432
  return this._renderer.renderModel(mimeModel);
1371
1433
  }
1372
- return Promise.resolve(void 0);
1434
+ return Promise.resolve();
1373
1435
  }
1374
1436
  /**
1375
1437
  * Clone the cell, using the same model.
@@ -1380,7 +1442,8 @@ export class MarkdownCell extends AttachmentsCell {
1380
1442
  model: this.model,
1381
1443
  contentFactory: this.contentFactory,
1382
1444
  rendermime: this._rendermime,
1383
- placeholder: false
1445
+ placeholder: false,
1446
+ translator: this.translator
1384
1447
  });
1385
1448
  }
1386
1449
  }
@@ -1406,6 +1469,8 @@ export class RawCell extends Cell {
1406
1469
  constructor(options) {
1407
1470
  super(options);
1408
1471
  this.addClass(RAW_CELL_CLASS);
1472
+ const trans = this.translator.load('jupyterlab');
1473
+ this.node.setAttribute('aria-label', trans.__('Raw Cell Content'));
1409
1474
  }
1410
1475
  /**
1411
1476
  * Clone the cell, using the same model.
@@ -1415,7 +1480,8 @@ export class RawCell extends Cell {
1415
1480
  return new constructor({
1416
1481
  model: this.model,
1417
1482
  contentFactory: this.contentFactory,
1418
- placeholder: false
1483
+ placeholder: false,
1484
+ translator: this.translator
1419
1485
  });
1420
1486
  }
1421
1487
  }