diff --git a/IPython/core/inputtransformer.py b/IPython/core/inputtransformer.py
index 9036add8a..3fdc64160 100644
--- a/IPython/core/inputtransformer.py
+++ b/IPython/core/inputtransformer.py
@@ -120,25 +120,18 @@ class TokenInputTransformer(InputTransformer):
     """
     def __init__(self, func):
         self.func = func
-        self.current_line = ""
-        self.line_used = False
+        self.buf = []
         self.reset_tokenizer()
-    
+
     def reset_tokenizer(self):
-        self.tokenizer = generate_tokens(self.get_line)
-    
-    def get_line(self):
-        if self.line_used:
-            raise TokenError
-        self.line_used = True
-        return self.current_line
-    
+        it = iter(self.buf)
+        self.tokenizer = generate_tokens(it.__next__)
+
     def push(self, line):
-        self.current_line += line + "\n"
-        if self.current_line.isspace():
+        self.buf.append(line + '\n')
+        if all(l.isspace() for l in self.buf):
             return self.reset()
-        
-        self.line_used = False
+
         tokens = []
         stop_at_NL = False
         try:
@@ -158,13 +151,13 @@ def push(self, line):
         return self.output(tokens)
     
     def output(self, tokens):
-        self.current_line = ""
+        self.buf.clear()
         self.reset_tokenizer()
         return untokenize(self.func(tokens)).rstrip('\n')
     
     def reset(self):
-        l = self.current_line
-        self.current_line = ""
+        l = ''.join(self.buf)
+        self.buf.clear()
         self.reset_tokenizer()
         if l:
             return l.rstrip('\n')

diff --git a/IPython/core/tests/test_inputtransformer.py b/IPython/core/tests/test_inputtransformer.py
index 27e67d8dd..2aa0670d5 100644
--- a/IPython/core/tests/test_inputtransformer.py
+++ b/IPython/core/tests/test_inputtransformer.py
@@ -389,6 +389,11 @@ def test_assemble_python_lines():
        (u"2,", None),
        (None, u"a = [1,\n2,"),
       ],
+      [(u"a = '''", None),  # Test line continuation within a multi-line string
+       (u"abc\\", None),
+       (u"def", None),
+       (u"'''", u"a = '''\nabc\\\ndef\n'''"),
+      ],
     ] + syntax_ml['multiline_datastructure']
     for example in tests:
         transform_checker(example, ipt.assemble_python_lines)

End of multiline string that contains a backslash-terminated line is not recognized
IPython 5.0/PTK1.0.5 does not recognize that

```
"""
foo\
bar
"""
```

is a full string and that it should execute the typed-in string after that point.

IPython/core/tests/test_inputtransformer.py::test_assemble_python_lines
IPython/core/tests/test_inputtransformer.py::test_assign_system IPython/core/tests/test_inputtransformer.py::test_assign_magic IPython/core/tests/test_inputtransformer.py::test_classic_prompt IPython/core/tests/test_inputtransformer.py::test_ipy_prompt IPython/core/tests/test_inputtransformer.py::test_assemble_logical_lines IPython/core/tests/test_inputtransformer.py::test_help_end IPython/core/tests/test_inputtransformer.py::test_escaped_noesc IPython/core/tests/test_inputtransformer.py::test_escaped_shell IPython/core/tests/test_inputtransformer.py::test_escaped_help IPython/core/tests/test_inputtransformer.py::test_escaped_magic IPython/core/tests/test_inputtransformer.py::test_escaped_quote IPython/core/tests/test_inputtransformer.py::test_escaped_quote2 IPython/core/tests/test_inputtransformer.py::test_escaped_paren IPython/core/tests/test_inputtransformer.py::test_cellmagic IPython/core/tests/test_inputtransformer.py::test_has_comment IPython/core/tests/test_inputtransformer.py::test_token_input_transformer