Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve multiline spaces for code blocks #347

Closed
victory-sokolov opened this issue May 19, 2023 · 5 comments
Closed

Preserve multiline spaces for code blocks #347

victory-sokolov opened this issue May 19, 2023 · 5 comments

Comments

@victory-sokolov
Copy link

Hello, was wondering if it's possible to make stripMultispaces as a boolean flag for the parserOptions of the extract method, so stripMultispaces could be an optional argument

In specific cases when I'm extracting HTML that has code blocks that need to have multi spaces preserved, in order to maintain formatted code blocks.

Maybe you have any other ideas on how this can be achieved?

Thanks!

@ndaidong
Copy link
Collaborator

@victory-sokolov thank you for your idea. Could you explain more detail and suggest some links to test? I consider that if that is a specific case, we can simply use transformation.

@victory-sokolov
Copy link
Author

Not sure if it will be straightforward to implement it using custom transformation.

Here is an example of the extracted code block

import { useTheme } from 'next-themes';   const ThemeChanger = () => {  const { theme, setTheme } = useTheme();    return (  <div>  The current theme is: {theme}  <button onClick={() => setTheme('light')}>Light Mode</button>  <button onClick={() => setTheme('dark')}>Dark Mode</button>  </div>  ); };

and this is the original code copied from the dev console (site)

import { useTheme } from 'next-themes';
 
const ThemeChanger = () => {
  const { theme, setTheme } = useTheme();
 
  return (
    <div>
      The current theme is: {theme}
      <button onClick={() => setTheme('light')}>Light Mode</button>
      <button onClick={() => setTheme('dark')}>Dark Mode</button>
    </div>
  );
};

In general code, blocks have 4 spaces for nested blocks, but when an article is being scrapped it has only one, I guess this is because of the stripMultispaces. Maybe you have other ideas how those spaces can be preserved

Thanks in advance.

@ndaidong
Copy link
Collaborator

@victory-sokolov yeah, you are right. It's because of stripMultispaces. Let me see how we can make it as a configurable option.

ndaidong added a commit that referenced this issue May 21, 2023
- Fix issue #347
- Update dependencies
@ndaidong ndaidong mentioned this issue May 21, 2023
@victory-sokolov
Copy link
Author

@ndaidong Awesome thanks a lot! Now code blocks are formatted properly.
Thanks once again!

@ndaidong
Copy link
Collaborator

@victory-sokolov nice to see it works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants