Skip to content

Commit

Permalink
auto format plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaroldi committed Jan 31, 2025
1 parent 5f67c49 commit f50a6e5
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export class AutoFormatPlugin implements EditorPlugin {
const formatOptions: FormatContentModelOptions = {
changeSource: '',
apiName: '',
getChangeData: () => null,
};
formatTextSegmentBeforeSelectionMarker(
editor,
Expand Down Expand Up @@ -147,11 +148,17 @@ export class AutoFormatPlugin implements EditorPlugin {
}

if (autoLink || autoTel || autoMailto) {
shouldLink = !!promoteLink(previousSegment, paragraph, {
const linkSegment = promoteLink(previousSegment, paragraph, {
autoLink,
autoTel,
autoMailto,
});
const anchorNode = createAnchor(
linkSegment?.link?.format?.href || '',
linkSegment?.text || ''
);
formatOptions.getChangeData = () => anchorNode;
shouldLink = !!linkSegment;

if (shouldLink) {
context.canUndoByBackspace = true;
Expand Down Expand Up @@ -270,3 +277,10 @@ const getChangeSource = (shouldList: boolean, shouldHyphen: boolean, shouldLink:
? ChangeSource.AutoLink
: '';
};

const createAnchor = (url: string, text: string) => {
const anchor = document.createElement('a');
anchor.href = url;
anchor.textContent = text;
return anchor;
};

0 comments on commit f50a6e5

Please sign in to comment.