Skip to content

Commit

Permalink
remove unwanted spacing around the list in block editor (#19521)
Browse files Browse the repository at this point in the history
* remove unwanted spacing around the list in block editor

* fix spacing issue

---------

Co-authored-by: karanh37 <[email protected]>
  • Loading branch information
Ashish8689 and karanh37 authored Jan 28, 2025
1 parent 33c107d commit 13f3d19
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { getTextFromHtmlString } from './BlockEditorUtils';
import {
getHtmlStringFromMarkdownString,
getTextFromHtmlString,
} from './BlockEditorUtils';

describe('getTextFromHtmlString', () => {
it('should return empty string when input is undefined', () => {
Expand Down Expand Up @@ -72,3 +75,45 @@ describe('getTextFromHtmlString', () => {
expect(getTextFromHtmlString(input)).toBe(output);
});
});

describe('getHtmlStringFromMarkdownString', () => {
it('should return the same string if input is already HTML', () => {
const input = '<p>Hello World</p>';

expect(getHtmlStringFromMarkdownString(input)).toBe(input);
});

it('should convert markdown to HTML', () => {
const input = 'Hello **World**';
const expectedOutput = '<p>Hello <strong>World</strong></p>';

expect(getHtmlStringFromMarkdownString(input)).toBe(expectedOutput);
});

it('should handle empty string', () => {
expect(getHtmlStringFromMarkdownString('')).toBe('');
});

it('should preserve special characters in markdown', () => {
const input = 'Hello & World! @ #$%^';
const expectedOutput = '<p>Hello &amp; World! @ #$%^</p>';

expect(getHtmlStringFromMarkdownString(input)).toBe(expectedOutput);
});

it('should handle complex markdown structure', () => {
const input = `
## Demo Title
Small Subtitle.
- Item 1
- Item 2
`;
const expectedOutput = `
<pre><code>##DemoTitleSmallSubtitle.-Item1-Item2</code></pre>
`;

expect(getHtmlStringFromMarkdownString(input).replace(/\s+/g, '')).toBe(
expectedOutput.replace(/\s+/g, '')
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,20 @@ const _convertMarkdownStringToHtmlString = new Showdown.Converter({
ellipsis: false,
});

export const getHtmlStringFromMarkdownString = (content: string) => {
return isHTMLString(content)
? content
: _convertMarkdownStringToHtmlString.makeHtml(content);
};

/**
* Set the content of the editor
* @param editor The editor instance
* @param newContent The new content to set
*/
export const setEditorContent = (editor: Editor, newContent: string) => {
// Convert the markdown string to an HTML string
const htmlString = _convertMarkdownStringToHtmlString.makeHtml(newContent);
const htmlString = getHtmlStringFromMarkdownString(newContent);

editor.commands.setContent(htmlString);

Expand Down

0 comments on commit 13f3d19

Please sign in to comment.