Zim

copy paste in plain text instead of wiki format

Bug #512243 reported by pm
16
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Zim
Fix Released
Medium
Unassigned

Bug Description

version: Zim 0.43
platform: linux - debian/sid

When pasting text from notebook to 3rd party application (like kwrite or eclipse), formatting characters are also copied, which is really annoying in case of formatted code samples.

how to repoduce:

Create zim note with text "bold text", and after that apply bold formatting on it. Copy this formatted text into your favourite editor, and a result you will have **bold text**.

Revision history for this message
Mark Alan (malan) wrote :

[while using zim_0.43_all.deb @ Ubuntu 9.10]

I can confirm that.
Pasting from a Zim page into a Linux terminal or a text editor, also pastes:
a) the formating codes (** **, __ __, == ==, etc), if the source was bold, italic, underlined, etc
b) a newline after the pasted text (this is particularly annoying when trying to paste code snippets from a Zim page into a Linux terminal).

Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote :

This is intended behavior. It can be useful, e.g. when pasting a page into a plain text email.

 Probably it should be configurable by a preference.

Changed in zim:
status: New → Incomplete
Revision history for this message
Mark Alan (malan) wrote :

It would be nice to have a checkbox at Edit->Preferences->Editing with something like:
   [ ] Disable Zim formating codes and end-of-line newlines in pasted content

While at it... as we already have CTRL-D (current date & time insertion) at our disposal, it would also be nice to have a checkbox at Edit->Preferences->Editing with something like:
   [ ] Disable automatic insertion of 'date of creation' when creating new pages

   To have clean pages by default, I have to use the following Linux command, each time I (re)install Zim:
         sudo sed -i '/^Created /d' /usr/share/zim/templates/wiki/_New.txt

Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote : Re: [Bug 512243] Re: copy paste and formatting

@mark: Please separate discussions, this bug report is not about the
template for new files. Instead of changing the template everytime,
you can store a copy in ~/.local/zim/templates/wiki and it will
override the one installed in /usr/share.

Revision history for this message
pm (piotr-marnik) wrote : Re: copy paste and formatting

What are You thinking about additional option in context menu? Something like 'copy with/without formatting'. While choosing between those two proposals, frequency of usage should be taken into consideration.

If more common use case is copy paste without formatting, then extra copy option for copying with formatting should be available. Otherwise opposite scenario should be used.

My personal opinion is that usually is used 'normal' copy mode (i.e. without preserve formatting).

Revision history for this message
Mark Alan (malan) wrote :

@ Jaap
I agree with your point about separate discussions;
But the bug title was just asking for it: it is "copy paste and formatting", and my suggestion was all about copy (from the system) and pasting (into each new page created) a a variable formated in a given way (Created [% strftime("%A %d %B %Y") %]);
I did follow your hint and did:
   mkdir -p ~/.local/zim/templates/wiki
   cp -fv /usr/share/zim/templates/wiki/_New.txt ~/.local/zim/templates/wiki/
   sed -i '/^Created /d' ~/.local/zim/templates/wiki/_New.txt
... and, even after killing and rebooting Zim, it does not work.

@pm
I, too, think that the normal non-formated paste operation is what most users use.
Regarding the option to put it in the context menu, I am like Jaap, I do to prefer the standard way of doing things.
And here the standard way seems to be to put the non standard thing (the option to "paste w/ Zim formating") in Edit->Preferences->Editing, and leave the context menu plain and simple.

Revision history for this message
pm (piotr-marnik) wrote :

@Mark

Ok let leave context menu plain and simple. But in case of intended (but not very often) usage of copying with formatting, users will digg somewhere in preferences, to change option, copy&paste, change option back to unformatted (assuming that formatted copying is rare action).

Instead i propose to add new option to 'Edit' menu, something like 'Copy with formatting'. In this way context menu will be uncluttered, and advanced copy action will be easily available via main menu bar.

Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote : Re: [Bug 512243] Re: copy paste and formatting

@mark: I'm sorry, but these topics are not related at all, please
discuss in normal email and I'll help you set up the template

Revision history for this message
Mark Alan (malan) wrote : Re: copy paste and formatting

@pm
That seems a good proposal

@Jaap
OK.

Revision history for this message
MadMud (matthias-edelhoff) wrote :

If this is bugging you as much as me here a quick hack until this is resolved:
in
zim/gui/clipboard.py line 175
change:
   dumper = get_format('wiki').Dumper()
to
   dumper = get_format('plain').Dumper()

as for the suggested feature, I am all for it.
technically I guess we need a wiki target and a new keybinding, should not be too hard. If I can actually pill it off I will send a patch

Revision history for this message
Mark Alan (malan) wrote :

@MadMud

=> As per you suggestion, using the following patch avoids the wiki formating codes in the pasted content:

+++ /usr/share/pyshared/zim/gui/clipboard.py
@@ -174,3 +174,3 @@
   elif id == TEXT_TARGET_ID:
- dumper = get_format('wiki').Dumper()
+ dumper = get_format('plain').Dumper()
    text = ''.join( dumper.dump(parsetree) ).encode('utf-8')

=> Now, if we could get rid of that that annoying newline (\n) at the end of each pasted content.
Have you found any way of avoiding that too?

Revision history for this message
MadMud (matthias-edelhoff) wrote :

@Mark
Seems that this is done on purpose:
zim/parsing.py lines 251 and 252 do it:

  if lines and not lines[-1].endswith('\n'):
   lines[-1] += '\n'

if you commet this the newline at the end will vanish. Now, I have no idea why this is done in the first place, so perhaps it is safer to check if the actual last elemt of the TextBuffer ends on '\n'. If it does not we could strip the additional newline only for the yopy/pasting part of the code.
Pehaps one of the devs could comment?

Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote :

Need to improve dumper for plain text before I can submit this change. In it's current form it does not support lists and indenting.

Revision history for this message
Mark Alan (malan) wrote :

Well, while waiting, the following solves the problem for me:

sudo sed -i '/[ \t]*lines\[-1\] +=/s/+=.*/= lines[-1]/' /usr/share/pyshared/zim/parsing.py

Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote :

@mark alan: I think what you are trying to fix with that expression is the trailing newline. That fix is actually applied already, see bug #510701.

This bug report is about wiki formatting in general for copy-paste to external applications.

Revision history for this message
Mark Alan (malan) wrote :

@Jaap
I've just installed zim_0.44_all.deb and it looks good.
I see that the '\n' and other small bugs in the search functions have been correct too.
Searched terms are now highlighted too.

Zim does not stop getting better.
Keep up the good work!

summary: - copy paste and formatting
+ copy paste and formatting in plain text instead of wiki format
summary: - copy paste and formatting in plain text instead of wiki format
+ copy paste in plain text instead of wiki format
Changed in zim:
status: Incomplete → Confirmed
importance: Undecided → Medium
tags: added: integration missing papercut
Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote :

Fixed in rev370

Copy pasting now by default in plain text
  * Added preference to set default back to wiki
  * Added context menu for "Copy As Wiki/Text" depending on the default

Changed in zim:
status: Confirmed → Fix Committed
Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote :

Released in zim 0.51

Changed in zim:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.